Skip to content

Commit 57d6614

Browse files
committed
black
1 parent eb9a2d2 commit 57d6614

16 files changed

Lines changed: 722 additions & 436 deletions

bench/benchmark_dumps.py

Lines changed: 89 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,157 +10,182 @@
1010

1111
from .util import read_fixture_obj, read_fixture_str
1212

13+
1314
def orjson_dumps(obj):
1415
return _orjson_dumps(obj)
1516

17+
1618
def ujson_dumps(obj):
17-
return _ujson_dumps(obj).encode('utf-8')
19+
return _ujson_dumps(obj).encode("utf-8")
20+
1821

1922
def rapidjson_dumps(obj):
20-
return _rapidjson_dumps(obj).encode('utf-8')
23+
return _rapidjson_dumps(obj).encode("utf-8")
24+
2125

2226
def json_dumps(obj):
23-
return _json_dumps(obj).encode('utf-8')
27+
return _json_dumps(obj).encode("utf-8")
28+
2429

2530
def simplejson_dumps(obj):
26-
return _simplejson_dumps(obj).encode('utf-8')
31+
return _simplejson_dumps(obj).encode("utf-8")
32+
2733

2834
def test_dumps_canada_orjson(benchmark):
29-
benchmark.group = 'canada.json serialization'
30-
benchmark.extra_info['lib'] = 'orjson'
35+
benchmark.group = "canada.json serialization"
36+
benchmark.extra_info["lib"] = "orjson"
3137
data = read_fixture_obj("canada.json.xz")
32-
benchmark.extra_info['correct'] = json_loads(orjson_dumps(data)) == data
38+
benchmark.extra_info["correct"] = json_loads(orjson_dumps(data)) == data
3339
benchmark(orjson_dumps, data)
3440

41+
3542
def test_dumps_canada_ujson(benchmark):
36-
benchmark.group = 'canada.json serialization'
37-
benchmark.extra_info['lib'] = 'ujson'
43+
benchmark.group = "canada.json serialization"
44+
benchmark.extra_info["lib"] = "ujson"
3845
data = read_fixture_obj("canada.json.xz")
39-
benchmark.extra_info['correct'] = json_loads(ujson_dumps(data)) == data
46+
benchmark.extra_info["correct"] = json_loads(ujson_dumps(data)) == data
4047
benchmark(ujson_dumps, data)
4148

49+
4250
def test_dumps_canada_json(benchmark):
43-
benchmark.group = 'canada.json serialization'
44-
benchmark.extra_info['lib'] = 'json'
51+
benchmark.group = "canada.json serialization"
52+
benchmark.extra_info["lib"] = "json"
4553
data = read_fixture_obj("canada.json.xz")
46-
benchmark.extra_info['correct'] = json_loads(json_dumps(data)) == data
54+
benchmark.extra_info["correct"] = json_loads(json_dumps(data)) == data
4755
benchmark(json_dumps, data)
4856

57+
4958
def test_dumps_canada_rapidjson(benchmark):
50-
benchmark.group = 'canada.json serialization'
51-
benchmark.extra_info['lib'] = 'rapidjson'
59+
benchmark.group = "canada.json serialization"
60+
benchmark.extra_info["lib"] = "rapidjson"
5261
data = read_fixture_obj("canada.json.xz")
53-
benchmark.extra_info['correct'] = json_loads(rapidjson_dumps(data)) == data
62+
benchmark.extra_info["correct"] = json_loads(rapidjson_dumps(data)) == data
5463
benchmark(rapidjson_dumps, data)
5564

65+
5666
def test_dumps_canada_simplejson(benchmark):
57-
benchmark.group = 'canada.json serialization'
58-
benchmark.extra_info['lib'] = 'simplejson'
67+
benchmark.group = "canada.json serialization"
68+
benchmark.extra_info["lib"] = "simplejson"
5969
data = read_fixture_obj("canada.json.xz")
60-
benchmark.extra_info['correct'] = json_loads(simplejson_dumps(data)) == data
70+
benchmark.extra_info["correct"] = json_loads(simplejson_dumps(data)) == data
6171
benchmark(simplejson_dumps, data)
6272

73+
6374
def test_dumps_citm_catalog_orjson(benchmark):
64-
benchmark.group = 'citm_catalog.json serialization'
65-
benchmark.extra_info['lib'] = 'orjson'
75+
benchmark.group = "citm_catalog.json serialization"
76+
benchmark.extra_info["lib"] = "orjson"
6677
data = read_fixture_obj("citm_catalog.json.xz")
67-
benchmark.extra_info['correct'] = json_loads(orjson_dumps(data)) == data
78+
benchmark.extra_info["correct"] = json_loads(orjson_dumps(data)) == data
6879
benchmark(orjson_dumps, data)
6980

81+
7082
def test_dumps_citm_catalog_ujson(benchmark):
71-
benchmark.group = 'citm_catalog.json serialization'
72-
benchmark.extra_info['lib'] = 'ujson'
83+
benchmark.group = "citm_catalog.json serialization"
84+
benchmark.extra_info["lib"] = "ujson"
7385
data = read_fixture_obj("citm_catalog.json.xz")
74-
benchmark.extra_info['correct'] = json_loads(ujson_dumps(data)) == data
86+
benchmark.extra_info["correct"] = json_loads(ujson_dumps(data)) == data
7587
benchmark(ujson_dumps, data)
7688

89+
7790
def test_dumps_citm_catalog_json(benchmark):
78-
benchmark.group = 'citm_catalog.json serialization'
79-
benchmark.extra_info['lib'] = 'json'
91+
benchmark.group = "citm_catalog.json serialization"
92+
benchmark.extra_info["lib"] = "json"
8093
data = read_fixture_obj("citm_catalog.json.xz")
81-
benchmark.extra_info['correct'] = json_loads(json_dumps(data)) == data
94+
benchmark.extra_info["correct"] = json_loads(json_dumps(data)) == data
8295
benchmark(json_dumps, data)
8396

97+
8498
def test_dumps_citm_catalog_rapidjson(benchmark):
85-
benchmark.group = 'citm_catalog.json serialization'
86-
benchmark.extra_info['lib'] = 'rapidjson'
99+
benchmark.group = "citm_catalog.json serialization"
100+
benchmark.extra_info["lib"] = "rapidjson"
87101
data = read_fixture_obj("citm_catalog.json.xz")
88-
benchmark.extra_info['correct'] = json_loads(rapidjson_dumps(data)) == data
102+
benchmark.extra_info["correct"] = json_loads(rapidjson_dumps(data)) == data
89103
benchmark(rapidjson_dumps, data)
90104

105+
91106
def test_dumps_citm_catalog_simplejson(benchmark):
92-
benchmark.group = 'citm_catalog.json serialization'
93-
benchmark.extra_info['lib'] = 'simplejson'
107+
benchmark.group = "citm_catalog.json serialization"
108+
benchmark.extra_info["lib"] = "simplejson"
94109
data = read_fixture_obj("citm_catalog.json.xz")
95-
benchmark.extra_info['correct'] = json_loads(simplejson_dumps(data)) == data
110+
benchmark.extra_info["correct"] = json_loads(simplejson_dumps(data)) == data
96111
benchmark(simplejson_dumps, data)
97112

113+
98114
def test_dumps_github_orjson(benchmark):
99-
benchmark.group = 'github.json serialization'
100-
benchmark.extra_info['lib'] = 'orjson'
115+
benchmark.group = "github.json serialization"
116+
benchmark.extra_info["lib"] = "orjson"
101117
data = read_fixture_obj("github.json.xz")
102-
benchmark.extra_info['correct'] = json_loads(orjson_dumps(data)) == data
118+
benchmark.extra_info["correct"] = json_loads(orjson_dumps(data)) == data
103119
benchmark(orjson_dumps, data)
104120

121+
105122
def test_dumps_github_ujson(benchmark):
106-
benchmark.group = 'github.json serialization'
107-
benchmark.extra_info['lib'] = 'ujson'
123+
benchmark.group = "github.json serialization"
124+
benchmark.extra_info["lib"] = "ujson"
108125
data = read_fixture_obj("github.json.xz")
109-
benchmark.extra_info['correct'] = json_loads(ujson_dumps(data)) == data
126+
benchmark.extra_info["correct"] = json_loads(ujson_dumps(data)) == data
110127
benchmark(ujson_dumps, data)
111128

129+
112130
def test_dumps_github_json(benchmark):
113-
benchmark.group = 'github.json serialization'
114-
benchmark.extra_info['lib'] = 'json'
131+
benchmark.group = "github.json serialization"
132+
benchmark.extra_info["lib"] = "json"
115133
data = read_fixture_obj("github.json.xz")
116-
benchmark.extra_info['correct'] = json_loads(json_dumps(data)) == data
134+
benchmark.extra_info["correct"] = json_loads(json_dumps(data)) == data
117135
benchmark(json_dumps, data)
118136

137+
119138
def test_dumps_github_rapidjson(benchmark):
120-
benchmark.group = 'github.json serialization'
121-
benchmark.extra_info['lib'] = 'rapidjson'
139+
benchmark.group = "github.json serialization"
140+
benchmark.extra_info["lib"] = "rapidjson"
122141
data = read_fixture_obj("github.json.xz")
123-
benchmark.extra_info['correct'] = json_loads(rapidjson_dumps(data)) == data
142+
benchmark.extra_info["correct"] = json_loads(rapidjson_dumps(data)) == data
124143
benchmark(rapidjson_dumps, data)
125144

145+
126146
def test_dumps_github_simplejson(benchmark):
127-
benchmark.group = 'github.json serialization'
128-
benchmark.extra_info['lib'] = 'simplejson'
147+
benchmark.group = "github.json serialization"
148+
benchmark.extra_info["lib"] = "simplejson"
129149
data = read_fixture_obj("github.json.xz")
130-
benchmark.extra_info['correct'] = json_loads(simplejson_dumps(data)) == data
150+
benchmark.extra_info["correct"] = json_loads(simplejson_dumps(data)) == data
131151
benchmark(simplejson_dumps, data)
132152

153+
133154
def test_dumps_twitter_orjson(benchmark):
134-
benchmark.group = 'twitter.json serialization'
135-
benchmark.extra_info['lib'] = 'orjson'
155+
benchmark.group = "twitter.json serialization"
156+
benchmark.extra_info["lib"] = "orjson"
136157
data = read_fixture_obj("twitter.json.xz")
137-
benchmark.extra_info['correct'] = json_loads(orjson_dumps(data)) == data
158+
benchmark.extra_info["correct"] = json_loads(orjson_dumps(data)) == data
138159
benchmark(orjson_dumps, data)
139160

161+
140162
def test_dumps_twitter_ujson(benchmark):
141-
benchmark.group = 'twitter.json serialization'
142-
benchmark.extra_info['lib'] = 'ujson'
163+
benchmark.group = "twitter.json serialization"
164+
benchmark.extra_info["lib"] = "ujson"
143165
data = read_fixture_obj("twitter.json.xz")
144-
benchmark.extra_info['correct'] = json_loads(ujson_dumps(data)) == data
166+
benchmark.extra_info["correct"] = json_loads(ujson_dumps(data)) == data
145167
benchmark(ujson_dumps, data)
146168

169+
147170
def test_dumps_twitter_json(benchmark):
148-
benchmark.group = 'twitter.json serialization'
149-
benchmark.extra_info['lib'] = 'json'
171+
benchmark.group = "twitter.json serialization"
172+
benchmark.extra_info["lib"] = "json"
150173
data = read_fixture_obj("twitter.json.xz")
151-
benchmark.extra_info['correct'] = json_loads(json_dumps(data)) == data
174+
benchmark.extra_info["correct"] = json_loads(json_dumps(data)) == data
152175
benchmark(json_dumps, data)
153176

177+
154178
def test_dumps_twitter_rapidjson(benchmark):
155-
benchmark.group = 'twitter.json serialization'
156-
benchmark.extra_info['lib'] = 'rapidjson'
179+
benchmark.group = "twitter.json serialization"
180+
benchmark.extra_info["lib"] = "rapidjson"
157181
data = read_fixture_obj("twitter.json.xz")
158-
benchmark.extra_info['correct'] = json_loads(rapidjson_dumps(data)) == data
182+
benchmark.extra_info["correct"] = json_loads(rapidjson_dumps(data)) == data
159183
benchmark(rapidjson_dumps, data)
160184

185+
161186
def test_dumps_twitter_simplejson(benchmark):
162-
benchmark.group = 'twitter.json serialization'
163-
benchmark.extra_info['lib'] = 'simplejson'
187+
benchmark.group = "twitter.json serialization"
188+
benchmark.extra_info["lib"] = "simplejson"
164189
data = read_fixture_obj("twitter.json.xz")
165-
benchmark.extra_info['correct'] = json_loads(simplejson_dumps(data)) == data
190+
benchmark.extra_info["correct"] = json_loads(simplejson_dumps(data)) == data
166191
benchmark(simplejson_dumps, data)

0 commit comments

Comments
 (0)