Advertisement
Guest User

Untitled

a guest
Mar 4th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. def using_builtins():
  2.     x = range(10000)
  3.     a = min(x)
  4.     b = max(x)
  5.     avg = sum(x) / len(x)
  6.  
  7. def manual_search():
  8.     x = range(10000)
  9.     a = x[0]
  10.     b = x[0]
  11.     total = 0
  12.     for item in x:
  13.         if item < a: a = item
  14.         if item > b: b = item
  15.         total += item
  16.     avg = total / len(x)
  17.  
  18. import timeit
  19. print timeit.timeit(using_builtins, number=10000)
  20. print timeit.timeit(manual_search, number=10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement