fork download
  1. import time
  2. import numpy
  3. import random
  4.  
  5. n = 30000
  6. m = 1
  7.  
  8. t = time.time()
  9. for i in range(10 ** m):
  10. list((numpy.random.rand(n) * 10).astype(int))
  11. print("numpy way took %.3f seconds" % (time.time() - t))
  12.  
  13. t = time.time()
  14. for i in range(10 ** m):
  15. [int(random.random() * 10) for _ in range(n)]
  16. print("randint way took %.3f seconds" % (time.time() - t))
  17.  
Success #stdin #stdout 0.19s 29848KB
stdin
Standard input is empty
stdout
numpy way took 0.028 seconds
randint way took 0.075 seconds