Measure code execution time
timeit1.py
# -*- coding: utf-8 -*-
def test():
L = []
for i in range(100):
L.append(i)
if __name__ == '__main__':
import timeit
print(timeit.timeit("test()", setup="from __main__ import test"))
# 10.1292455843
timeit2.py
# -*- coding: utf-8 -*-
def test():
L = []
for i in range(10):
L.append(i)
if __name__ == '__main__':
import timeit
print(timeit.timeit("test()", setup="from __main__ import test"))
# 1.57425508033
Recommended Posts