i have simple test function need capture execution time using 'timeit' module, error
the function:
import timeit def test1(): l = [] in range(1000): l = l + [i] t1 = timeit.timer("test1()", "from __main__ import test1") print(t1.timeit(number=1000))
the error: c:\python34\lib\timeit.py:186: in timeit timing = self.inner(it, self.timer) :3: in inner ??? e
importerror: cannot import name 'test1' =========== 1 error in 0.03 seconds ==============
can guys me solution?
i think there couple of problems code. first make sure can import timeit. , have module. this, can run:
python -m timeit '"-".join(str(n) n in range(100))'
if execute fine sure have timeit module.
now regarding question. took liberty rewriting in cleaner way.
import timeit def append_list(): num_list = [] in range(1000): num_list.append(i) print(timeit.timeit(stmt=append_list, number=1000)) #number number of repetion of operation, in case, 1000 # can run print(timeit.timeit(stmt=append_list, number=1))
now, above wanted do, i.e calculate amount of time required append numbers 1 1000 list.
Comments
Post a Comment