Guest User

Untitled

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