forked from samuelcolvin/xdelta3-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperformance.py
More file actions
31 lines (25 loc) · 962 Bytes
/
performance.py
File metadata and controls
31 lines (25 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
To run:
curl https://ocw.mit.edu/ans7870/6/6.006/s08/lecturenotes/files/t8.shakespeare.txt > shakespeare.txt
cp shakespeare.txt shakespeare_changed.txt
vim shakespeare_changed.txt (and make some changes to shakespeare_changed.txt)
python performance.py
"""
from pathlib import Path
from statistics import mean, stdev
from time import time
import xdelta3
v1 = Path('shakespeare.txt').read_bytes()
v2 = Path('shakespeare_changed.txt').read_bytes()
times = []
for i in range(50):
start = time()
delta = xdelta3.encode(v1, v2, xdelta3.Flags.COMPLEVEL_1)
v22 = xdelta3.decode(v1, delta)
time_taken = (time() - start) * 1000
times.append(time_taken)
print(f'{i + 1:3} result_match={v2 == v22} time={time_taken:0.1f}ms')
print(f'\noriginal length: {len(v1)}')
print(f'changed length: {len(v2)}')
print(f'delta length: {len(delta)}')
print(f'mean time taken to encode and decode: {mean(times):0.3f}ms, stdev {stdev(times):0.3f}ms')