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.
- ssrjson_benchmark/__init__.py +21 -0
- ssrjson_benchmark/__main__.py +113 -0
- ssrjson_benchmark/_files/apache.json +3532 -0
- ssrjson_benchmark/_files/canada.json +56532 -0
- ssrjson_benchmark/_files/ctm.json +48951 -0
- ssrjson_benchmark/_files/github.json +1320 -0
- ssrjson_benchmark/_files/instruments.json +7395 -0
- ssrjson_benchmark/_files/mesh.json +3602 -0
- ssrjson_benchmark/_files/simple_object.json +11 -0
- ssrjson_benchmark/_files/simple_object_zh.json +11 -0
- ssrjson_benchmark/_files/truenull.json +1 -0
- ssrjson_benchmark/_files/tweet.json +135 -0
- ssrjson_benchmark/_files/twitter.json +15195 -0
- ssrjson_benchmark/_ssrjson_benchmark.so +0 -0
- ssrjson_benchmark/benchmark_impl.py +1190 -0
- ssrjson_benchmark/result_types.py +96 -0
- ssrjson_benchmark/template.md +14 -0
- ssrjson_benchmark-0.0.9.dist-info/METADATA +88 -0
- ssrjson_benchmark-0.0.9.dist-info/RECORD +22 -0
- ssrjson_benchmark-0.0.9.dist-info/WHEEL +6 -0
- ssrjson_benchmark-0.0.9.dist-info/licenses/LICENSE +21 -0
- ssrjson_benchmark-0.0.9.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import TYPE_CHECKING, Any
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BenchmarkResultBase(dict):
|
|
6
|
+
ATTRS = ()
|
|
7
|
+
DEFAULT_SECTION_CLS = dict
|
|
8
|
+
|
|
9
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
|
10
|
+
self[name] = value
|
|
11
|
+
|
|
12
|
+
def __getitem__(self, key: Any) -> Any:
|
|
13
|
+
try:
|
|
14
|
+
return super().__getitem__(key)
|
|
15
|
+
except KeyError:
|
|
16
|
+
cls = getattr(self.__class__, "DEFAULT_SECTION_CLS", None)
|
|
17
|
+
if cls is None:
|
|
18
|
+
raise
|
|
19
|
+
obj = cls()
|
|
20
|
+
super().__setitem__(key, obj)
|
|
21
|
+
return obj
|
|
22
|
+
|
|
23
|
+
def __getattr__(self, attrname):
|
|
24
|
+
try:
|
|
25
|
+
return self.__getitem__(attrname)
|
|
26
|
+
except KeyError:
|
|
27
|
+
raise AttributeError(attrname)
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def parse(cls, j):
|
|
31
|
+
self = cls()
|
|
32
|
+
for k, v in j.items():
|
|
33
|
+
if k in cls.ATTRS:
|
|
34
|
+
setattr(self, k, v)
|
|
35
|
+
else:
|
|
36
|
+
setattr(self, k, cls.DEFAULT_SECTION_CLS.parse(v))
|
|
37
|
+
return self
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class BenchmarkResultPerFileTargetLib(BenchmarkResultBase):
|
|
41
|
+
speed: int
|
|
42
|
+
ratio: float
|
|
43
|
+
ATTRS = ("speed", "ratio")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class BenchmarkResultPerFileTarget(BenchmarkResultBase):
|
|
47
|
+
DEFAULT_SECTION_CLS = BenchmarkResultPerFileTargetLib
|
|
48
|
+
ATTRS = ("ssrjson_bytes_per_sec",)
|
|
49
|
+
ssrjson_bytes_per_sec: float
|
|
50
|
+
|
|
51
|
+
if TYPE_CHECKING:
|
|
52
|
+
|
|
53
|
+
def __getitem__(self, key: str) -> BenchmarkResultPerFileTargetLib: ...
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class BenchmarkResultPerFile(BenchmarkResultBase):
|
|
57
|
+
DEFAULT_SECTION_CLS = BenchmarkResultPerFileTarget
|
|
58
|
+
ATTRS = (
|
|
59
|
+
"byte_size",
|
|
60
|
+
"pyunicode_size",
|
|
61
|
+
"pyunicode_kind",
|
|
62
|
+
"pyunicode_is_ascii",
|
|
63
|
+
)
|
|
64
|
+
byte_size: int
|
|
65
|
+
pyunicode_size: int
|
|
66
|
+
pyunicode_kind: int
|
|
67
|
+
pyunicode_is_ascii: bool
|
|
68
|
+
|
|
69
|
+
if TYPE_CHECKING:
|
|
70
|
+
|
|
71
|
+
def __getitem__(self, key: str) -> BenchmarkResultPerFileTarget: ...
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class BenchmarkFinalResult(BenchmarkResultBase):
|
|
75
|
+
categories: list[str]
|
|
76
|
+
results: dict[str, dict[str, BenchmarkResultPerFile]]
|
|
77
|
+
filenames: set[str]
|
|
78
|
+
processbytesgb: float
|
|
79
|
+
perbinbytesmb: int
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def parse(cls, j: dict):
|
|
83
|
+
ret = cls()
|
|
84
|
+
ret.categories = j["categories"]
|
|
85
|
+
ret.results = dict()
|
|
86
|
+
ret.filenames = j["filenames"]
|
|
87
|
+
ret.processbytesgb = j["processbytesgb"]
|
|
88
|
+
ret.perbinbytesmb = j["perbinbytesmb"]
|
|
89
|
+
for k, v in j["results"].items():
|
|
90
|
+
ret.results[k] = dict()
|
|
91
|
+
for a, b in v.items():
|
|
92
|
+
ret.results[k][a] = BenchmarkResultPerFile.parse(b)
|
|
93
|
+
return ret
|
|
94
|
+
|
|
95
|
+
def dumps(self):
|
|
96
|
+
return json.dumps(self, ensure_ascii=False, indent=4)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# ssrJSON benchmark Report
|
|
2
|
+
|
|
3
|
+
REV: `{REV}`
|
|
4
|
+
Python: `{PYTHON}`
|
|
5
|
+
Orjson: `{ORJSON_VER}`
|
|
6
|
+
MsgSpec: `{MSGSPEC_VER}`
|
|
7
|
+
Ujson: `{UJSON_VER}`
|
|
8
|
+
Generated time: {TIME}
|
|
9
|
+
OS: {OS}
|
|
10
|
+
SIMD flag: {SIMD_FLAGS}
|
|
11
|
+
Chipset: {CHIPSET}
|
|
12
|
+
Memory: {MEM}
|
|
13
|
+
Process(GB): {PROCESS_MEM}
|
|
14
|
+
PerBin(MB): {PER_BIN_MEM}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ssrjson-benchmark
|
|
3
|
+
Version: 0.0.9
|
|
4
|
+
Summary: benchmark of ssrJSON
|
|
5
|
+
Author-email: Eritque Arcus <eritque-arcus@ikuyo.dev>, Antares <antares0982@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Nambers/ssrJSON-benchmark
|
|
8
|
+
Project-URL: Issues, https://github.com/Nambers/ssrJSON-benchmark/issues
|
|
9
|
+
Project-URL: Repository, https://github.com/Nambers/ssrJSON-benchmark.git
|
|
10
|
+
Keywords: ssrjson,benchmark,json
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: System :: Benchmark
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: ssrjson>=0.0.9
|
|
21
|
+
Requires-Dist: orjson
|
|
22
|
+
Requires-Dist: msgspec
|
|
23
|
+
Requires-Dist: ujson
|
|
24
|
+
Requires-Dist: matplotlib
|
|
25
|
+
Requires-Dist: psutil; platform_machine == "x86_64"
|
|
26
|
+
Requires-Dist: svglib
|
|
27
|
+
Requires-Dist: reportlab
|
|
28
|
+
Requires-Dist: py-cpuinfo
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# ssrJSON-benchmark
|
|
32
|
+
|
|
33
|
+
<div align="center">
|
|
34
|
+
|
|
35
|
+
[](https://pypi.org/project/ssrjson-benchmark/) [](https://pypi.org/project/ssrjson-benchmark/)
|
|
36
|
+
|
|
37
|
+
The [ssrJSON](https://github.com/Antares0982/ssrjson) benchmark repository.
|
|
38
|
+
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
## Benchmark Results
|
|
42
|
+
|
|
43
|
+
The benchmark results can be found in [website results](https://ikuyo.dev/ssrJSON-benchmark/) or [GitHub results](https://github.com/Nambers/ssrJSON-benchmark/tree/main/results). Contributing your benchmark result is welcomed.
|
|
44
|
+
|
|
45
|
+
Quick jump for
|
|
46
|
+
|
|
47
|
+
* [x86-64-v4, AVX512](https://github.com/Nambers/ssrJSON-benchmark/tree/main/results/AVX512)
|
|
48
|
+
* [x86-64-v3, AVX2](https://github.com/Nambers/ssrJSON-benchmark/tree/main/results/AVX2)
|
|
49
|
+
* [x86-64-v2, SSE4.2](https://github.com/Nambers/ssrJSON-benchmark/tree/main/results/SSE4.2)
|
|
50
|
+
* [aarch64, NEON](https://github.com/Nambers/ssrJSON-benchmark/tree/main/results/NEON)
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# you may need to install `svglib`, `reportlab` and `py-cpuinfo` as well
|
|
56
|
+
pip install ssrjson-benchmark
|
|
57
|
+
python -m ssrjson_benchmark
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Benchmark options
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
usage: python -m ssrjson_benchmark [-h] [-f FILE] [-d IN_DIR] [-m] [--no-pdf] [--process-gigabytes PROCESS_GIGABYTES]
|
|
64
|
+
[--bin-process-megabytes BIN_PROCESS_MEGABYTES] [--out-dir OUT_DIR]
|
|
65
|
+
|
|
66
|
+
options:
|
|
67
|
+
-h, --help show this help message and exit
|
|
68
|
+
-f, --file FILE Use a result JSON file generated in previous benchmark to print report. Will skip all tests.
|
|
69
|
+
-d, --in-dir IN_DIR Benchmark JSON files directory. If not provided, use the files bundled in this package.
|
|
70
|
+
-m, --markdown Generate Markdown report
|
|
71
|
+
--no-pdf Don't generate PDF report
|
|
72
|
+
--process-gigabytes PROCESS_GIGABYTES
|
|
73
|
+
Total gigabytes to process per test case, default 0.1 (float)
|
|
74
|
+
--bin-process-megabytes BIN_PROCESS_MEGABYTES
|
|
75
|
+
Maximum bytes to process per bin, default 32 (int)
|
|
76
|
+
--out-dir OUT_DIR Output directory for reports
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Notes
|
|
80
|
+
|
|
81
|
+
* This repository conducts benchmarking using json, [ujson](https://github.com/ultrajson/ultrajson), [msgspec](https://github.com/jcrist/msgspec), [orjson](https://github.com/ijl/orjson), and [ssrJSON](https://github.com/Antares0982/ssrjson). The benchmark for `dumps_to_str` aims to produce a `str` object. If a JSON library's dumps-related interface only outputs a `bytes` object, it will be substituted with dumps followed by a single `decode("utf-8")` operation. Similarly, for the `dumps_to_bytes` test, if the JSON library's dumps-related interface only outputs a `str` object, it will be replaced with dumps followed by a single `encode("utf-8")` operation.
|
|
82
|
+
* To ensure the accuracy of benchmark results, this repository differentiates between scenarios with and without UTF-8 caches when testing `dumps_to_bytes`. For `dumps_to_str` and `loads`, since these methods are unrelated to encoding `str` objects to UTF-8, the data sources do not involve any UTF-8 cache, and no distinction is made in their tests.
|
|
83
|
+
* Cache writing of ssrJSON is disabled globally when running benchmark.
|
|
84
|
+
* We use `orjson.dumps` to create UTF-8 cache for all benchmark targets.
|
|
85
|
+
* Test with UTF-8 cache is skipped when the whole JSON object is ASCII.
|
|
86
|
+
* The performance of JSON encoding is primarily constrained by the speed of writing to the buffer, whereas decoding performance is mainly limited by the frequent invocation of CPython interfaces for object creation. During decoding, both ssrJSON and orjson employ short key caching to reduce the number of object creations, and this caching mechanism is global in both libraries. As a result, decoding benchmark tests may not accurately reflect the conditions encountered in real-world production environments.
|
|
87
|
+
* The files simple_object.json and simple_object_zh.json do not represent real-world data; they are used to compare the performance of the fast path. Therefore, the benchmark results from these test cases should not be interpreted as indicative of actual performance in production environment.
|
|
88
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
ssrjson_benchmark/__init__.py,sha256=CxJ2-wwiINL7dz6K13CC6BwMi6nTAckZ1Ri_X0FOq8E,422
|
|
2
|
+
ssrjson_benchmark/__main__.py,sha256=mNVuixTjENSsk6LqFxPs_MIM_W3k0QgYDg4xm5wn3tA,3227
|
|
3
|
+
ssrjson_benchmark/_ssrjson_benchmark.so,sha256=-pEDyeASzmeKjhkS_4NtrpxNUc8QgVCJEZ1vL8wXObs,22825
|
|
4
|
+
ssrjson_benchmark/benchmark_impl.py,sha256=zl0KSXQwBL07xES4JYLjke8DMbUzweEBCpM1-0dZEDs,37911
|
|
5
|
+
ssrjson_benchmark/result_types.py,sha256=mzuXhJSE8lXq2f980vbsUX6jI6-zFGftnj1Js4sPsro,2594
|
|
6
|
+
ssrjson_benchmark/template.md,sha256=Y6ufs0ROQjgeqYSecbnKPd5cUuXzfor2yCUKI5GY9sk,353
|
|
7
|
+
ssrjson_benchmark/_files/apache.json,sha256=PWRTA_Ndfp2EY4IiCNvyrNtIXjsYlX9WMNnq5-yjQGM,126371
|
|
8
|
+
ssrjson_benchmark/_files/canada.json,sha256=HTO1LmhieUT3Sz4gqwG8-jkaV-qc-nlurQ0BxDVgTnw,3489802
|
|
9
|
+
ssrjson_benchmark/_files/ctm.json,sha256=AYxJ_k_SsSSoljPfosNHIVuF4myQlFbBTGg9H3JAk2A,1691678
|
|
10
|
+
ssrjson_benchmark/_files/github.json,sha256=ZTI6ZBUhKHTXhutl6_TnnTGuMIsfkHofV5It4oBDL_s,67831
|
|
11
|
+
ssrjson_benchmark/_files/instruments.json,sha256=IUZpcByg5XZuwPtATZlcStk1n1sx0tLYFE0nQjJnUjg,193873
|
|
12
|
+
ssrjson_benchmark/_files/mesh.json,sha256=SRBCOA_kaG1FbpJWb7n5R-7H0p74FfH5MD4ig73fzx0,752407
|
|
13
|
+
ssrjson_benchmark/_files/simple_object.json,sha256=Zaalit6WeTnSkn52yhHZXPbnHMZalaXi7PIlCpt7qeg,36902
|
|
14
|
+
ssrjson_benchmark/_files/simple_object_zh.json,sha256=UOmpDly_tpkCVL-tyxn_1sabMJn1ttcs3Zu2T0dvIE8,110486
|
|
15
|
+
ssrjson_benchmark/_files/truenull.json,sha256=enl_cy6qWa8b7bdVpx3-e0k6X9BFe_aCPot1rEquGiU,12000
|
|
16
|
+
ssrjson_benchmark/_files/tweet.json,sha256=vRuGAaWuYiQDHGiaujUYY3nuK9UFNWEeloZe95VWNAI,4994
|
|
17
|
+
ssrjson_benchmark/_files/twitter.json,sha256=s4v0svEREPZ-TOogwUf3PvhE9DG4K_7fivfSaYdwYHs,755433
|
|
18
|
+
ssrjson_benchmark-0.0.9.dist-info/METADATA,sha256=P14e8XNJvF0IVrNG35HwqZEB_e_J7uQXYFEsxS3Rrt8,5206
|
|
19
|
+
ssrjson_benchmark-0.0.9.dist-info/WHEEL,sha256=sLnxkimgGZnkHfiVG0CKXk3cbEzmkkBUHrkKJEO9o6g,151
|
|
20
|
+
ssrjson_benchmark-0.0.9.dist-info/top_level.txt,sha256=l1O9IjI1lR5DczhKv9O-GeItgq5HZySDOI5KjfFfvq8,37
|
|
21
|
+
ssrjson_benchmark-0.0.9.dist-info/RECORD,,
|
|
22
|
+
ssrjson_benchmark-0.0.9.dist-info/licenses/LICENSE,sha256=O43ZquZ3FGDxi9aUS-Kqz5gHy1QX9bvvMDv9JOpjUZg,1070
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Eritque arcus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|