Guest User

Untitled

a guest
Mar 7th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. def almost_not_slow():
  2.     CHANNELS = 16
  3.     SAMPLE_LENGTH = CHANNELS // 8
  4.     BUFFER = 256
  5.    
  6.     vals = {}
  7.     for i in range(2**CHANNELS):
  8.         vals[struct.pack('H', i)] = tuple(b'+1' if e == '1' else b'-1' for e in list("{:016b}".format(i)))
  9.    
  10.     with open('largefile.dat', 'rb') as f:
  11.         data = f.read()
  12.     size = len(data)
  13.     print("Data size: %d" % size)
  14.    
  15.     out_file = open('largefile_dump.dat', 'wb')
  16.     out_list = [out_file]*CHANNELS
  17.    
  18.     samples = ()
  19.    
  20.     for i in range(0, size, SAMPLE_LENGTH):
  21.         if i % (1024*1024) == 0: print("i = %d" % i)
  22.         samples = samples + (vals[data[i:i+SAMPLE_LENGTH]],)
  23.         if len(samples) == BUFFER:
  24.             for channel in range(CHANNELS):
  25.                 s = b'\n'.join(r[channel] for r in samples)
  26.                 out_list[channel].write(s)
  27.             samples = ()
  28.    
  29.     if samples:
  30.         for channel in range(CHANNELS):
  31.             s = b'\n'.join(r[channel] for r in samples)
  32.             out_list[channel].write(s)
  33.  
  34.     out_file.close()
Add Comment
Please, Sign In to add comment