psf / pyperf

Toolkit to run Python benchmarks
http://pyperf.readthedocs.io/
MIT License
799 stars 78 forks source link

pyperf does not support multiple statements #127

Closed idiomaticrefactoring closed 2 years ago

idiomaticrefactoring commented 2 years ago
import pyperf
t = []
code='''
for i in range(10):
    t.append(i)
'''
import pyperf

runner = pyperf.Runner()
runner.timeit(code,globals=globals())
print(t)

It occurs errors: ValueError: newline characters are not allowed in metadata values: 'for i in range(10):\n t.append(i)'

Someone knows how to record time for multiple statements?

sweeneyde commented 2 years ago

Look again at the signature of timeit:

>>> import pyperf
>>> help(pyperf.Runner.timeit)
Help on function timeit in module pyperf._runner:

timeit(self, name, stmt=None, setup='pass', teardown='pass', inner_loops=None, duplicate=None, metadata=None, globals=None)

First is name. You can't have a name with newlines. You can have a stmt with newlines.

vstinner commented 2 years ago

Right. You misused the timeit(name, stmt, ...) API. I close the issue.