ssrjson-benchmark 0.0.9__cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ from . import _ssrjson_benchmark as internal
2
+ from .benchmark_impl import (
3
+ generate_report_markdown,
4
+ generate_report_pdf,
5
+ run_benchmark,
6
+ )
7
+
8
+ try:
9
+ from importlib.metadata import version
10
+
11
+ __version__ = version("ssrjson-benchmark")
12
+ except Exception:
13
+ __version__ = "0.0.0"
14
+
15
+ __all__ = [
16
+ "generate_report_markdown",
17
+ "generate_report_pdf",
18
+ "internal",
19
+ "run_benchmark",
20
+ "__version__",
21
+ ]
@@ -0,0 +1,113 @@
1
+ import sys
2
+
3
+
4
+ def main():
5
+ try:
6
+ import msgspec
7
+ import orjson
8
+ import ssrjson
9
+ import ujson
10
+ except ImportError:
11
+ print("Please install required packages: msgspec, orjson, ssrjson, ujson")
12
+ return 1
13
+ import argparse
14
+ import json
15
+ import os
16
+ import pathlib
17
+
18
+ from .benchmark_impl import (
19
+ generate_report_markdown,
20
+ generate_report_pdf,
21
+ parse_file_result,
22
+ run_benchmark,
23
+ )
24
+
25
+ parser = argparse.ArgumentParser()
26
+
27
+ parser.add_argument(
28
+ "-f",
29
+ "--file",
30
+ help="Use a result JSON file generated in previous benchmark to print report. Will skip all tests.",
31
+ required=False,
32
+ default=None,
33
+ )
34
+ parser.add_argument(
35
+ "-d",
36
+ "--in-dir",
37
+ help="Benchmark JSON files directory. If not provided, use the files bundled in this package.",
38
+ required=False,
39
+ )
40
+ parser.add_argument(
41
+ "-m",
42
+ "--markdown",
43
+ help="Generate Markdown report",
44
+ required=False,
45
+ action="store_true",
46
+ )
47
+ parser.add_argument(
48
+ "--no-pdf",
49
+ help="Don't generate PDF report",
50
+ required=False,
51
+ action="store_true",
52
+ )
53
+ parser.add_argument(
54
+ "--process-gigabytes",
55
+ help="Total gigabytes to process per test case, default 0.1 (float)",
56
+ required=False,
57
+ default=0.1,
58
+ type=float,
59
+ )
60
+ parser.add_argument(
61
+ "--bin-process-megabytes",
62
+ help="Maximum bytes to process per bin, default 32 (int)",
63
+ required=False,
64
+ default=32,
65
+ type=int,
66
+ )
67
+ parser.add_argument(
68
+ "--out-dir",
69
+ help="Output directory for reports",
70
+ required=False,
71
+ default=os.getcwd(),
72
+ )
73
+ args = parser.parse_args()
74
+ skip_tests = bool(args.file)
75
+ if skip_tests and args.no_pdf and not args.markdown:
76
+ print("Nothing to do.")
77
+ return 0
78
+
79
+ _benchmark_files_dir = args.in_dir
80
+ if not _benchmark_files_dir:
81
+ _benchmark_files_dir = os.path.join(
82
+ os.path.dirname(os.path.abspath(__file__)), "_files"
83
+ )
84
+ benchmark_files_dir = sorted(pathlib.Path(_benchmark_files_dir).glob("*.json"))
85
+ if not benchmark_files_dir:
86
+ print(f"No benchmark file found using given path: {_benchmark_files_dir}")
87
+ return 1
88
+
89
+ if skip_tests:
90
+ with open(args.file, "rb") as f:
91
+ result_ = json.load(f)
92
+ result = parse_file_result(result_)
93
+ file = args.file.split("/")[-1]
94
+ else:
95
+ process_bytes = int(args.process_gigabytes * 1024 * 1024 * 1024)
96
+ bin_process_bytes = args.bin_process_megabytes * 1024 * 1024
97
+ if process_bytes <= 0 or bin_process_bytes <= 0:
98
+ print("process-gigabytes and bin-process-megabytes must be positive.")
99
+ return 1
100
+ result, file = run_benchmark(
101
+ benchmark_files_dir, process_bytes, bin_process_bytes
102
+ )
103
+ file = file.split("/")[-1]
104
+
105
+ if args.markdown:
106
+ generate_report_markdown(result, file, args.out_dir)
107
+ if not args.no_pdf:
108
+ generate_report_pdf(result, file, args.out_dir)
109
+ return 0
110
+
111
+
112
+ if __name__ == "__main__":
113
+ sys.exit(main())