File: runner.py

package info (click to toggle)
python-msgspec 0.19.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,356 kB
  • sloc: javascript: 23,944; ansic: 20,540; python: 20,465; makefile: 29; sh: 19
file content (44 lines) | stat: -rw-r--r-- 907 bytes parent folder | download
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
import importlib
import json
import timeit
import resource
import sys
import gc

library, path = sys.argv[1:3]

with open(path, "rb") as f:
    json_data = f.read()

initial_rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss

mod = importlib.import_module(f"benchmarks.bench_validation.bench_{library}")

msg = mod.decode(json_data)

gc.collect()
timer = timeit.Timer("func(data)", setup="", globals={"func": mod.encode, "data": msg})
n, t = timer.autorange()
encode_time = t / n

del msg

gc.collect()
timer = timeit.Timer(
    "func(data)", setup="", globals={"func": mod.decode, "data": json_data}
)
n, t = timer.autorange()
decode_time = t / n

max_rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss


report = json.dumps(
    {
        "label": mod.label,
        "encode": encode_time,
        "decode": decode_time,
        "memory": (max_rss - initial_rss) / 1024,
    }
)
print(report)