-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/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: | ||
file_utf8 = 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 | ||
|
||
val = loads(file_utf8) | ||
|
||
mem_after = proc.memory_info().rss | ||
|
||
mem_diff = mem_after - mem_before | ||
|
||
print(f"{mem_before},{mem_diff}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
|
||
import io | ||
import subprocess | ||
|
||
from tabulate import tabulate | ||
|
||
buf = io.StringIO() | ||
|
||
headers = ("Library", "import, read() RSS (MiB)", "loads() increase in RSS (MiB)") | ||
|
||
LIBRARIES = ("orjson", "ujson", "rapidjson", "json", "simplejson") | ||
|
||
FIXTURES = ("canada.json", "citm_catalog.json", "github.json", "twitter.json") | ||
|
||
for fixture in sorted(FIXTURES, reverse=True): | ||
table = [] | ||
buf.write("\n" + "#### " + fixture + "\n\n") | ||
for lib_name in LIBRARIES: | ||
proc = subprocess.Popen( | ||
("bench/run_mem", f"data/{fixture}.xz", lib_name), stdout=subprocess.PIPE | ||
) | ||
output = proc.stdout.readline().decode("utf-8").split(",") | ||
mem_base = int(output[0]) / 1024 / 1024 | ||
mem_diff = int(output[1]) / 1024 / 1024 | ||
table.append((lib_name, f"{mem_base:,.1f}", f"{mem_diff:,.1f}")) | ||
buf.write(tabulate(table, headers, tablefmt="grid") + "\n") | ||
|
||
print( | ||
buf.getvalue() | ||
.replace("-", "") | ||
.replace("=", "-") | ||
.replace("+", "|") | ||
.replace("||||", "") | ||
.replace("\n\n", "\n") | ||
) |