Last active
August 29, 2015 14:05
-
-
Save hyunjun/108701fa3436710c39fd to your computer and use it in GitHub Desktop.
timeit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.python.org/2/library/timeit.html | |
>>> def foo(n): | |
... res = [] | |
... for i in range(n): res.append(n) | |
... return res | |
... | |
>>> def foo2(n): | |
... return [i for i in range(n)] | |
... | |
>>> foo(10) == foo2(10) | |
False | |
>>> def foo(n): | |
... res = [] | |
... for i in range(n): res.append(i) | |
... return res | |
... | |
>>> def foo2(n): | |
... return [i for i in range(n)] | |
... | |
>>> foo(10) == foo2(10) | |
True | |
>>> import timeit | |
>>> timeit.timeit(stmt='foo(10000)', setup='from __main__ import foo', number=100) | |
0.11489105224609375 | |
>>> timeit.timeit(stmt='foo2(10000)', setup='from __main__ import foo2', number=100) | |
0.04136300086975098 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment