-
Notifications
You must be signed in to change notification settings - Fork 2
/
bench.py
executable file
·65 lines (47 loc) · 1.58 KB
/
bench.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env python
from __future__ import print_function
import gzip
import time
import gzippy
def timer(name, runs=1):
'''Yield run times, collecting timing information.'''
print(name)
print('=' * len(name))
times = []
for run in range(runs):
start = -time.time()
yield run
start += time.time()
times.append(start)
print('Average of %s runs: %s\n' % (runs, sum(times) / len(times)))
split = [b'This is some example content'] * 100000
joined = b'\n'.join(split)
for _ in timer('Gzip single write', 5):
with gzip.open('example.gz', 'wb') as fout:
fout.write(joined)
for _ in timer('Gzippy single write', 5):
with gzippy.open('example.gz', 'wb') as fout:
fout.write(joined)
for _ in timer('Gzip with repeated writes', 5):
with gzip.open('example.gz', 'wb') as fout:
for element in split:
fout.write(element)
for _ in timer('Gzip with repeated writes', 5):
with gzippy.open('example.gz', 'wb') as fout:
for element in split:
fout.write(element)
# Read in an example file
with gzip.open('example.gz', 'wb') as fout:
fout.write(joined)
for _ in timer('Gzip with single read', 5):
with gzip.open('example.gz', 'rb') as fin:
fin.read()
for _ in timer('Gzippy with single read', 5):
with gzippy.open('example.gz', 'rb') as fin:
fin.read()
for _ in timer('Gzip iterlines', 5):
with gzip.open('example.gz', 'rb') as fin:
list(fin)
for _ in timer('Gzippy iterlines', 5):
with gzippy.open('example.gz', 'rb') as fin:
list(fin)