-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.py
46 lines (39 loc) · 1.07 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
import benchmark
import json
import jsoncanon
class CanonBench(benchmark.Benchmark):
""" Benchmarks jsoncanon (with and without list sorting) against the json
module for performance comparison """
def setUp(self):
self.size = 25000
self.doc = {
"a": [
10,
{},
{
"hello": 1,
"zzz": []
},
"bob",
"agnes"
],
"1": 55.7,
"3": {
"xxxxx": {},
"ggg": []
},
"b": None,
"c": True,
"d": False
}
def test_jsoncanon(self):
for i in xrange(self.size):
jsoncanon.dumps(self.doc)
def test_jsoncanon_sorting_lists(self):
for i in xrange(self.size):
jsoncanon.dumps(self.doc, sort_lists=True)
def test_json_module(self):
for i in xrange(self.size):
json.dumps(self.doc)
if __name__ == "__main__":
benchmark.main(format="rst")