Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import time
- import multiprocessing
- from multiprocessing import Pool
- # Initial params
- piece_size = 16 # KB
- # cores in system
- multiplier = 4
- errors = 0
- starttime = time()
- # 2 equal by size, but different by content files
- file1 = open('etalon.mkv', 'rb')
- file2 = open('startplus.mkv', 'rb')
- # get byte piece of 2 files, and compare them
- def check(r1, r2, i):
- global errors
- if r1[i:i + piece_size] != r2[i:i + piece_size]:
- errors += 1
- return
- if __name__ == '__main__':
- # 4 process threads (opt for 4 core cpu)
- pool = Pool(processes = multiplier)
- r1 = file1.read(piece_size * multiplier)
- r2 = file2.read(piece_size * multiplier)
- while r1:
- for i in range(0, piece_size * multiplier, piece_size):
- pool.apply(check, [r1,r2,i])
- r1 = file1.read(piece_size)
- r2 = file2.read(piece_size)
- print('errors:', errors)
- print('Running time: ', time() - starttime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement