Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypyc made my code slower #1041

Open
Dreamsorcerer opened this issue Dec 4, 2023 · 0 comments
Open

mypyc made my code slower #1041

Dreamsorcerer opened this issue Dec 4, 2023 · 0 comments

Comments

@Dreamsorcerer
Copy link

Dreamsorcerer commented Dec 4, 2023

Bug Report

I really wasn't expecting this result. But, after writing a simple solution to the first advent of code problem, I thought I would see what performance can be gained by compiling it with mypyc. It was about 20% slower!

> python3 -m timeit 'from test import solve1' 'solve1()'
500 loops, best of 5: 439 usec per loop
> python3 -m timeit 'from test import solve1' 'solve1()'
500 loops, best of 5: 438 usec per loop
> mypyc  --strict test.py
...
> python3 -m timeit 'from test import solve1' 'solve1()'
500 loops, best of 5: 513 usec per loop
> python3 -m timeit 'from test import solve1' 'solve1()'
500 loops, best of 5: 513 usec per loop

To Reproduce

def solve1() -> int:
    result = 0
    for l in data:
        for c in l:
            if c.isdigit():
                result += int(c) * 10
                break
        for c in reversed(l):
            if c.isdigit():
                result += int(c)
                break
    return result

Full file with input data included:
mypy-test.txt

Expected Behavior

At worst, equal performance to pure Python.

Your Environment

  • Mypy version used: 1.7.1
  • Mypy command-line flags: --strict
  • Python version used: 3.12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant