Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import time
- nmax = 10000
- x = 1
- start = time()
- while x < nmax: # 10K = 0.01s, 100K = 0.13s, 1M = 1.7s
- y = []
- tmp = x * x * x
- while tmp > 0:
- y.append(tmp % 10)
- tmp /= 10
- x += 1
- print "numerical", time() - start
- x = 1
- start = time()
- while x < nmax: # 10K = 0.08s, 100K = 0.8s, 1M = 11s
- y = map(int,str(x*x*x))
- x += 1
- print "map", time() - start
- x = 1
- start = time()
- while x < nmax: # 10K = 0.03s, 100K = 0.3s, 1M = 3s
- y = [int(ch) for ch in str(x*x*x)]
- x += 1
- print "comprehension", time() - start
- x = 1
- start = time()
- while x < nmax: # 10K = 0.05s, 100K = 0.28s, 1M = 3.4s
- y = []
- for ch in str(x*x*x):
- y.append(int(ch))
- x += 1
- print "iterative", time() - start
- x = 1
- start = time()
- while x < nmax: # 10K = 0.04s, 100K = 0.33s, 1M = 3.8s
- y = []
- for ch in str(x*x*x):
- y += [int(ch)]
- x += 1
- print "+ list", time() - start
Add Comment
Please, Sign In to add comment