Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import timeit
  2. def main():
  3.     import h5py, cyrandom
  4.     allchr =  "".join((chr(i) for i in range(33,127)))
  5.     pspool = [[cyrandom.choice(allchr) for _ in range(cyrandom.randint(10, 100))] for x in range(100000)]
  6.    
  7.     chunkl = []    
  8.     for _ in range(5000000):
  9.         b1 = cyrandom.choice(pspool)
  10.         cyrandom.shuffle(b1)
  11.         chunkl.append(''.join(b1).encode('utf-8'))
  12.        
  13.     f = h5py.File('h5.h5','w')    
  14.     for k in range(50000000//5000000):        
  15.         l = [str(k).encode('utf-8')]
  16.         # cyrandom.shuffle(chunkl)    
  17.         print(k)        
  18.         f.create_dataset(str(k), data=chunkl+l,)
  19.     del chunkl
  20.     f.close()
  21.    
  22. def query():
  23.     import h5py
  24.     f = h5py.File('h5.h5','a')
  25.     wbw = set(f['0'].value)
  26.     count = []
  27.     for k in f.keys():
  28.         print(k)
  29.         for x in f[k].value:
  30.             if x not in wbw:
  31.                 count.append(x)
  32.     print(count)
  33.     f.close()
  34.    
  35. print(timeit.timeit(main, number=1))
  36. print(timeit.timeit(query, number=1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement