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

perf breaks on benchmarking Enum creation #49

Closed
tirkarthi opened this Issue Jan 8, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@tirkarthi
Copy link

tirkarthi commented Jan 8, 2019

I was trying to use perf for benchmarking python/cpython#11318 and tried below example that works with timeit but breaks while using perf. Not sure if this statement cannot be benchmarked as per perf implementation internals. I thought to file this anyway. Feel free to close this if it's invalid.

Using timeit

$ python3 -m timeit -s 'from enum import Enum;' "Enum('Animal', 'ANT BEE CAT DOG')"
2000 loops, best of 5: 121 usec per loop

Using perf

$ python3 -m perf timeit -s 'from enum import Enum;' "Enum('Animal', 'ANT BEE CAT DOG')"
Error when running timeit benchmark:

Statement:
"Enum('Animal', 'ANT BEE CAT DOG')"

Setup:
'from enum import Enum;'

Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_timeit.py", line 203, in bench_timeit
    runner.bench_time_func(name, timer.time_func, **kwargs)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_runner.py", line 458, in bench_time_func
    return self._main(task)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_runner.py", line 423, in _main
    bench = self._worker(task)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_runner.py", line 397, in _worker
    run = task.create_run()
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_worker.py", line 293, in create_run
    self.compute()
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_worker.py", line 331, in compute
    WorkerTask.compute(self)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_worker.py", line 280, in compute
    self.calibrate_loops()
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_worker.py", line 245, in calibrate_loops
    calibrate_loops=True)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_worker.py", line 76, in _compute_values
    raw_value = self.task_func(self, self.loops)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_runner.py", line 454, in task_func
    return time_func(loops, *args)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_timeit.py", line 109, in time_func
    return inner(it, timer)
  File "<timeit-src>", line 6, in inner
    Enum('Animal', 'ANT BEE CAT DOG')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/enum.py", line 311, in __call__
    return cls._create_(value, names, module=module, qualname=qualname, type=type, start=start)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/enum.py", line 429, in _create_
    module = sys._getframe(2).f_globals['__name__']
KeyError: '__name__'
Error when running timeit benchmark:

Statement:
"Enum('Animal', 'ANT BEE CAT DOG')"

Setup:
'from enum import Enum;'

Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_timeit.py", line 203, in bench_timeit
    runner.bench_time_func(name, timer.time_func, **kwargs)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_runner.py", line 458, in bench_time_func
    return self._main(task)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_runner.py", line 428, in _main
    bench = self._master()
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_runner.py", line 551, in _master
    bench = Master(self).create_bench()
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_master.py", line 221, in create_bench
    worker_bench, run = self.create_worker_bench()
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_master.py", line 120, in create_worker_bench
    suite = self.create_suite()
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_master.py", line 110, in create_suite
    suite = self.spawn_worker(self.calibrate_loops, 0)
  File "/Users/karthikeyansingaravelan/stuff/python/py37-venv/lib/python3.7/site-packages/perf/_master.py", line 97, in spawn_worker
    % (cmd[0], exitcode))
RuntimeError: /Users/karthikeyansingaravelan/stuff/python/py37-venv/bin/python3 failed with exit code 1
@vstinner

This comment has been minimized.

Copy link
Owner

vstinner commented Jan 11, 2019

It's a bug in enum.Enum, not in perf. I reported the bug upstream: https://bugs.python.org/issue35717

@vstinner vstinner closed this Jan 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment