psf/pyperf

pyperf does not support multiple statements

idiomaticrefactoring opened this issue · 2 comments

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?

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.

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