Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import numpy.random
- import string
- import time
- import os
- from threading import Thread
- l = list(string.ascii_letters)
- s = time.time()
- t_gen = 0
- t_wrt = 0
- chars = 0
- thr = None
- with open("rnd_str.txt", 'w+') as f:
- f.write("")
- def wrt(data):
- global t_wrt, chars
- t = time.time()
- with open("rnd_str.txt", 'a') as f:
- data.tofile(f)
- t_wrt += time.time() - t
- chars += data.shape[0]
- for i in range(30):
- t = time.time()
- data = np.random.choice(l, 2*1024*1024)
- t_gen += time.time() - t
- if thr and thr.isAlive():
- thr.join()
- thr = Thread(target=wrt, args=(data,))
- thr.start()
- size = os.path.getsize("rnd_str.txt")
- print("\nTotal time: %.3f\nChars: %d\nFile size: %d\nGeneration time: %.3f\nWriting time: %.3f" % (
- time.time() - s, chars, size, t_gen, t_wrt))
Advertisement
Add Comment
Please, Sign In to add comment