Reputation: 4925
When trying to use the Python built-in module 'timeit' as follows:
timeit.Timer('print "hi"').timeit()
it prints more than one line; why is that? It keeps printing "hi" endlessly:
hi
hi
hi
hi
...
Upvotes: 5
Views: 1622
Reputation: 78620
timeit
is designed to test extremely short code snippets, so it runs the code many times and averages them. As a default, it runs it 1000000 times.
You can change this by running it as follows:
timeit.Timer('print "hi"').timeit(number=1)
Upvotes: 14