Advertisement
Guest User

Untitled

a guest
Mar 20th, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. import numpy as np
  2. import numpy.random
  3. import string
  4. import time
  5. import os
  6.  
  7. l = list(string.ascii_letters)
  8.  
  9. s = time.time()
  10. t_gen = 0
  11. t_wrt = 0
  12. chars = 0
  13.  
  14. with open("rnd_str.txt", 'w+') as f:
  15.     f.write("")
  16.  
  17. for i in range(30):
  18.     t = time.time()
  19.     data = np.random.choice(l, 2*1024*1024)
  20.     t_gen += time.time() - t
  21.  
  22.     t = time.time()
  23.     with open("rnd_str.txt", 'a') as f:
  24.         data.tofile(f)
  25.     t_wrt += time.time() - t
  26.     chars += data.shape[0]
  27.  
  28. size = os.path.getsize("rnd_str.txt")
  29.  
  30. print("\nTotal time: %.3f\nChars: %d\nFile size: %d\nGeneration time: %.3f\nWriting time: %.3f" % (
  31.     time.time() - s, chars, size, t_gen, t_wrt))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement