Created
July 15, 2014 19:13
-
-
Save matyushkin/346407f071a9f7ad934a to your computer and use it in GitHub Desktop.
range/xrange comparison (python 2.7)
This file contains hidden or 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
| import time | |
| from matplotlib import pyplot as plt | |
| n = 9 | |
| def who_is_best(func): | |
| t0 = time.time() | |
| for i in func: | |
| i = i**2 | |
| delta_t = time.time() - t0 | |
| return delta_t | |
| x = xrange(n) | |
| range_y = [] | |
| xrange_y = [] | |
| for i in x: | |
| y = who_is_best(range(10**i)) | |
| range_y.append(y) | |
| y = who_is_best(xrange(10**i)) | |
| xrange_y.append(y) | |
| plt.plot(x, range_y, 'bo-') | |
| plt.plot(x, xrange_y, 'r+-') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment