forked from ijl/orjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_mem
More file actions
executable file
·46 lines (32 loc) · 951 Bytes
/
Copy pathrun_mem
File metadata and controls
executable file
·46 lines (32 loc) · 951 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import sys
import lzma
import gc
import psutil
filename = sys.argv[1]
with lzma.open(filename, "r") as fileh:
fixture = fileh.read()
proc = psutil.Process()
lib_name = sys.argv[2]
if lib_name == "json":
from json import dumps, loads
elif lib_name == "orjson":
from orjson import dumps, loads
elif lib_name == "rapidjson":
from rapidjson import dumps, loads
elif lib_name == "simplejson":
from simplejson import dumps, loads
elif lib_name == "ujson":
from ujson import dumps, loads
else:
raise NotImplementedError
gc.collect()
mem_before = proc.memory_info().rss
for _ in range(100):
val = loads(fixture)
mem_after = proc.memory_info().rss
mem_diff = mem_after - mem_before
from json import loads as json_loads
correct = 1 if (json_loads(fixture) == json_loads(dumps(loads(fixture)))) else 0
print(f"{mem_before},{mem_diff},{correct}")