Advertisement
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
- l = list(string.ascii_letters)
- s = time.time()
- t_gen = 0
- t_wrt = 0
- chars = 0
- with open("rnd_str.txt", 'w+') as f:
- f.write("")
- for i in range(30):
- t = time.time()
- data = np.random.choice(l, 2*1024*1024)
- t_gen += time.time() - t
- t = time.time()
- with open("rnd_str.txt", 'a') as f:
- data.tofile(f)
- t_wrt += time.time() - t
- chars += data.shape[0]
- 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
Advertisement