Timeit timing a python function -
i trying time below function, shows me error, can't import name val_in_range, what's error, there other method better?
import timeit x = 10000000 def val_in_range(x, val): return val in range(x) print (val_in_range(x,x/2)) timeit.timeit( 'val_in_range(x,x/2)', 'from __main__ import val_in_range, x', number=10)
output:
true traceback (most recent call last): file "python", line 11, in <module> file "<timeit-src>", line 3, in inner importerror: cannot import name 'val_in_range'
replace timeit.timeit( 'val_in_range(x,x/2)', 'from __main__ import val_in_range, x', number=10)
with timeit.timeit(lambda:val_in_range(x,x/2), number=10)
you can print value directly using print
statement.
Comments
Post a Comment