Skip to content

Instantly share code, notes, and snippets.

@matyushkin
Created July 15, 2014 19:13
Show Gist options
  • Select an option

  • Save matyushkin/346407f071a9f7ad934a to your computer and use it in GitHub Desktop.

Select an option

Save matyushkin/346407f071a9f7ad934a to your computer and use it in GitHub Desktop.
range/xrange comparison (python 2.7)
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