-
Notifications
You must be signed in to change notification settings - Fork 12
/
benchmark.py
executable file
·49 lines (35 loc) · 1.31 KB
/
benchmark.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
import time
from tabulate import tabulate
from contextlib import contextmanager
from subjects import (marsh, rf, serp, strain, col, hand, loli, k, lim, tmarsh, avro, pickle, serpy)
from data import ParentTestObject
SUBJECTS = (marsh, rf, serp, strain, col, hand, loli, k, lim, tmarsh, avro, pickle, serpy)
test_object = ParentTestObject()
@contextmanager
def timer(tracker):
start = time.time()
yield
end = time.time()
tracker += [end - start]
def test_many(func, limit=1000):
for i in range(0, limit):
subject.serialization_func([test_object, test_object], True)
def test_one(func, limit=1000):
for i in range(0, limit):
subject.serialization_func(test_object, False)
table = []
for subject in SUBJECTS:
row = [subject.name]
test_many(subject.serialization_func, 2) # Warmup
with timer(row):
test_many(subject.serialization_func)
test_one(subject.serialization_func, 2) # Warmup
with timer(row):
test_one(subject.serialization_func)
table += [row]
table = sorted(table, key=lambda x: x[1] + x[2])
relative_base = min([x[1] + x[2] for x in table])
for row in table:
result = (row[1] + row[2]) / relative_base
row.append(result)
print(tabulate(table, headers=['Library', 'Many Objects (seconds)', 'One Object (seconds)', 'Relative']))