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

pyperf does not support multiple statements #127

Closed
idiomaticrefactoring opened this issue Apr 7, 2022 · 2 comments
Closed

pyperf does not support multiple statements #127

idiomaticrefactoring opened this issue Apr 7, 2022 · 2 comments

Comments

@idiomaticrefactoring
Copy link

idiomaticrefactoring commented Apr 7, 2022

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
Copy link

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
Copy link
Member

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

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

3 participants