SHARE
TWEET

Untitled

a guest Jan 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int* a = new int[10];
  2.    
  3. l = [1,2,3,4]
  4. l = range(10)
  5.    
  6. >>> [None for _ in range(10)]
  7. [None, None, None, None, None, None, None, None, None, None]
  8.    
  9. >>> [None]*10
  10. [None, None, None, None, None, None, None, None, None, None]
  11.    
  12. >>> x = []
  13. >>> for i in range(10):
  14. >>>    x.append(i)
  15.    
  16. >>> def initAndWrite_test():
  17. ...  x = [None]*10000
  18. ...  for i in range(10000):
  19. ...   x[i] = i
  20. ...
  21. >>> def initAndWrite2_test():
  22. ...  x = [None for _ in range(10000)]
  23. ...  for i in range(10000):
  24. ...   x[i] = i
  25. ...
  26. >>> def appendWrite_test():
  27. ...  x = []
  28. ...  for i in range(10000):
  29. ...   x.append(i)
  30.    
  31. >>> import timeit
  32. >>> for f in [initAndWrite_test, initAndWrite2_test, appendWrite_test]:
  33. ...  print('{} takes {} usec/loop'.format(f.__name__, timeit.timeit(f, number=1000)*1000))
  34. ...
  35. initAndWrite_test takes 714.596033096 usec/loop
  36. initAndWrite2_test takes 981.526136398 usec/loop
  37. appendWrite_test takes 908.597946167 usec/loop
  38.    
  39. initAndWrite_test takes 641.3581371307373 usec/loop
  40. initAndWrite2_test takes 1033.6499214172363 usec/loop
  41. appendWrite_test takes 895.9040641784668 usec/loop
  42.    
  43. import collections
  44. max_4_items = collections.deque([None] * 4, maxlen=4)
  45.    
  46. >>> l = [None] * 4
  47. >>> l
  48. [None, None, None, None]
  49.    
  50. from numpy import *
  51.  
  52. l = zeros(10)
  53.    
  54. your_list = [None]*size_required
  55.    
  56. fix_array = numpy.empty(n, dtype = object)
  57.    
  58. from array import array
  59. from itertools import repeat
  60.  
  61. a = array("i", repeat(0, 10))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top