ssrjson-benchmark 0.0.1__tar.gz → 0.0.1b0__tar.gz

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.

Potentially problematic release.


This version of ssrjson-benchmark might be problematic. Click here for more details.

Files changed (35) hide show
  1. {ssrjson_benchmark-0.0.1 → ssrjson_benchmark-0.0.1b0}/CMakeLists.txt +1 -1
  2. ssrjson_benchmark-0.0.1b0/PKG-INFO +60 -0
  3. {ssrjson_benchmark-0.0.1 → ssrjson_benchmark-0.0.1b0}/README.md +10 -14
  4. ssrjson_benchmark-0.0.1b0/setup.py +100 -0
  5. {ssrjson_benchmark-0.0.1 → ssrjson_benchmark-0.0.1b0}/src/benchmark.c +3 -3
  6. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/__init__.py +15 -0
  7. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/__main__.py +54 -0
  8. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/MotionsQuestionsAnswersQuestions2016.json +1 -0
  9. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/apache.json +3532 -0
  10. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/canada.json +56532 -0
  11. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/ctm.json +48951 -0
  12. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/github.json +1320 -0
  13. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/instruments.json +7395 -0
  14. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/mesh.json +3602 -0
  15. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/simple_object.json +11 -0
  16. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/simple_object_zh.json +11 -0
  17. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/truenull.json +1 -0
  18. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/tweet.json +135 -0
  19. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/_files/twitter.json +15195 -0
  20. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/benchmark_main.py +652 -0
  21. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark/template.md +10 -0
  22. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark.egg-info/PKG-INFO +60 -0
  23. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark.egg-info/SOURCES.txt +28 -0
  24. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark.egg-info/requires.txt +8 -0
  25. ssrjson_benchmark-0.0.1b0/src/ssrjson_benchmark.egg-info/top_level.txt +2 -0
  26. ssrjson_benchmark-0.0.1/PKG-INFO +0 -5
  27. ssrjson_benchmark-0.0.1/setup.py +0 -118
  28. ssrjson_benchmark-0.0.1/ssrjson_benchmark.egg-info/PKG-INFO +0 -5
  29. ssrjson_benchmark-0.0.1/ssrjson_benchmark.egg-info/SOURCES.txt +0 -11
  30. ssrjson_benchmark-0.0.1/ssrjson_benchmark.egg-info/top_level.txt +0 -1
  31. {ssrjson_benchmark-0.0.1 → ssrjson_benchmark-0.0.1b0}/LICENSE +0 -0
  32. {ssrjson_benchmark-0.0.1 → ssrjson_benchmark-0.0.1b0}/MANIFEST.in +0 -0
  33. {ssrjson_benchmark-0.0.1 → ssrjson_benchmark-0.0.1b0}/cmake/XcodeProperty.cmake +0 -0
  34. {ssrjson_benchmark-0.0.1 → ssrjson_benchmark-0.0.1b0}/setup.cfg +0 -0
  35. {ssrjson_benchmark-0.0.1 → ssrjson_benchmark-0.0.1b0/src}/ssrjson_benchmark.egg-info/dependency_links.txt +0 -0
@@ -66,7 +66,7 @@ add_library(ssrjson_benchmark SHARED ${SRC_FILES})
66
66
  target_link_libraries(ssrjson_benchmark PUBLIC ${Python3_LIBRARIES})
67
67
  set_target_properties(ssrjson_benchmark PROPERTIES PREFIX "")
68
68
  target_include_directories(ssrjson_benchmark PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> ${Python3_INCLUDE_DIRS})
69
-
69
+ set_target_properties(ssrjson_benchmark PROPERTIES OUTPUT_NAME "_ssrjson_benchmark")
70
70
  # ------------------------------------------------------------------------------
71
71
  if(XCODE)
72
72
  set(SSRJSON_BENCHMARK_FLAGS)
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: ssrjson_benchmark
3
+ Version: 0.0.1b0
4
+ Summary: Benchmark for ssrJSON
5
+ Description-Content-Type: text/markdown
6
+ License-File: LICENSE
7
+ Requires-Dist: ssrjson
8
+ Requires-Dist: orjson
9
+ Requires-Dist: matplotlib
10
+ Provides-Extra: all
11
+ Requires-Dist: svglib; extra == "all"
12
+ Requires-Dist: reportlab; extra == "all"
13
+ Requires-Dist: py-cpuinfo; extra == "all"
14
+ Dynamic: description
15
+ Dynamic: description-content-type
16
+ Dynamic: license-file
17
+ Dynamic: provides-extra
18
+ Dynamic: requires-dist
19
+ Dynamic: summary
20
+
21
+ # ssrJSON-benchmark
22
+
23
+ <div align="center">
24
+
25
+ [![PyPI - Version](https://img.shields.io/pypi/v/ssrjson-benchmark)](https://pypi.org/project/ssrjson-benchmark/) [![PyPI - Wheel](https://img.shields.io/pypi/wheel/ssrjson-benchmark)](https://pypi.org/project/ssrjson-benchmark/)
26
+
27
+ The [ssrJSON](https://github.com/Antares0982/ssrjson) benchmark repository.
28
+
29
+ </div>
30
+
31
+ ## Benchmark Results
32
+
33
+ The benchmark results can be found in [results](results). Contributing your benchmark result is welcomed.
34
+
35
+ Quick jump for
36
+
37
+ * [x86-64-v2, SSE4.2](results/SSE4.2)
38
+ * [x86-64-v3, AVX2](results/AVX2)
39
+ * [x86-64-v4, AVX512](results/AVX512)
40
+
41
+ ## Usage
42
+
43
+ ```bash
44
+ # you may need to install `svglib`, `reportlab` and `py-cpuinfo` as well
45
+ pip install ssrjson-benchmark
46
+ python -m ssrjson_benchmark
47
+ ```
48
+
49
+ ## Benchmark options
50
+
51
+ * `-m` output in Markdown instead of PDF.
52
+ * `-f <json_path>` used exists benchmark json result.
53
+ * `--process-bytes <bytes_num>` Total process bytes per test, default 1e8.
54
+
55
+ ## Notes
56
+
57
+ * This repository conducts benchmarking using json, orjson, and ssrJSON. The `dumps` benchmark produces str objects, comparing three operations: `json.dumps`, `orjson.dumps` followed by decode, and `ssrjson.dumps`. The `dumps_to_bytes` benchmark produces bytes objects, comparing three functions: `json.dumps` followed by encode, `orjson.dumps`, and `ssrjson.dumps_to_bytes`.
58
+ * When orjson handles non-ASCII strings, if the cache of the `PyUnicodeObject`’s UTF-8 representation does not exist, it invokes the `PyUnicode_AsUTF8AndSize` function to obtain the UTF-8 encoding. This function then caches the UTF-8 representation within the `PyUnicodeObject`. If the same `PyUnicodeObject` undergoes repeated encode-decode operations, subsequent calls after the initial one will execute more quickly due to this caching. However, in real-world production scenarios, it is uncommon to perform JSON encode-decode repeatedly on the exact same string object; even identical strings are unlikely to be the same object instance. To achieve benchmark results that better reflect practical use cases, we employ `ssrjson.run_unicode_accumulate_benchmark` and `benchmark_invalidate_dump_cache` functions, which ensure that new `PyUnicodeObject`s are different for each input every time. (ref: [orjson#586](https://github.com/ijl/orjson/issues/586))
59
+ * 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 cases. As a result, decoding benchmark tests may not accurately reflect the conditions encountered in real-world production environments.
60
+ * The files simple_object.json and simple_object_zh.json do not represent real-world data; they are solely used to compare the performance of the fast path. Therefore, the benchmark results should not be interpreted as indicative of actual performance.
@@ -1,7 +1,13 @@
1
1
  # ssrJSON-benchmark
2
2
 
3
+ <div align="center">
4
+
5
+ [![PyPI - Version](https://img.shields.io/pypi/v/ssrjson-benchmark)](https://pypi.org/project/ssrjson-benchmark/) [![PyPI - Wheel](https://img.shields.io/pypi/wheel/ssrjson-benchmark)](https://pypi.org/project/ssrjson-benchmark/)
6
+
3
7
  The [ssrJSON](https://github.com/Antares0982/ssrjson) benchmark repository.
4
8
 
9
+ </div>
10
+
5
11
  ## Benchmark Results
6
12
 
7
13
  The benchmark results can be found in [results](results). Contributing your benchmark result is welcomed.
@@ -14,17 +20,10 @@ Quick jump for
14
20
 
15
21
  ## Usage
16
22
 
17
- To generate a benchmark report, you need to install `ssrJSON` either by fetched [PyPi](https://pypi.org/project/ssrjson/) or built from [source](https://github.com/Antares0982/ssrjson), and toolkit(`ssrjson_benchmark`) from this repo by:
18
-
19
- ```bash
20
- python -m build
21
- pip install dist/*.whl
22
- ```
23
-
24
- Then run the benchmark script:
25
-
26
23
  ```bash
27
- python benchmark.py
24
+ # you may need to install `svglib`, `reportlab` and `py-cpuinfo` as well
25
+ pip install ssrjson-benchmark
26
+ python -m ssrjson_benchmark
28
27
  ```
29
28
 
30
29
  ## Benchmark options
@@ -36,9 +35,6 @@ python benchmark.py
36
35
  ## Notes
37
36
 
38
37
  * This repository conducts benchmarking using json, orjson, and ssrJSON. The `dumps` benchmark produces str objects, comparing three operations: `json.dumps`, `orjson.dumps` followed by decode, and `ssrjson.dumps`. The `dumps_to_bytes` benchmark produces bytes objects, comparing three functions: `json.dumps` followed by encode, `orjson.dumps`, and `ssrjson.dumps_to_bytes`.
39
- * The ssrJSON built with the `BUILD_BENCHMARK` option includes several additional C functions specifically designed for executing benchmarks. These functions utilize high-precision timing APIs, and within the loop, only the time spent on the actual `PyObject_Call` invocations is measured.
40
- * When orjson handles non-ASCII strings, if the cache of the `PyUnicodeObject`’s UTF-8 representation does not exist, it invokes the `PyUnicode_AsUTF8AndSize` function to obtain the UTF-8 encoding. This function then caches the UTF-8 representation within the `PyUnicodeObject`. If the same `PyUnicodeObject` undergoes repeated encode-decode operations, subsequent calls after the initial one will execute more quickly due to this caching. However, in real-world production scenarios, it is uncommon to perform JSON encode-decode repeatedly on the exact same string object; even identical strings are unlikely to be the same object instance. To achieve benchmark results that better reflect practical use cases, we employ `ssrjson.run_unicode_accumulate_benchmark` and `benchmark_invalidate_dump_cache` functions, which ensure that new `PyUnicodeObject`s are different for each input every time.
41
-
38
+ * When orjson handles non-ASCII strings, if the cache of the `PyUnicodeObject`’s UTF-8 representation does not exist, it invokes the `PyUnicode_AsUTF8AndSize` function to obtain the UTF-8 encoding. This function then caches the UTF-8 representation within the `PyUnicodeObject`. If the same `PyUnicodeObject` undergoes repeated encode-decode operations, subsequent calls after the initial one will execute more quickly due to this caching. However, in real-world production scenarios, it is uncommon to perform JSON encode-decode repeatedly on the exact same string object; even identical strings are unlikely to be the same object instance. To achieve benchmark results that better reflect practical use cases, we employ `ssrjson.run_unicode_accumulate_benchmark` and `benchmark_invalidate_dump_cache` functions, which ensure that new `PyUnicodeObject`s are different for each input every time. (ref: [orjson#586](https://github.com/ijl/orjson/issues/586))
42
39
  * 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 cases. As a result, decoding benchmark tests may not accurately reflect the conditions encountered in real-world production environments.
43
-
44
40
  * The files simple_object.json and simple_object_zh.json do not represent real-world data; they are solely used to compare the performance of the fast path. Therefore, the benchmark results should not be interpreted as indicative of actual performance.
@@ -0,0 +1,100 @@
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+
5
+ from setuptools import Extension, find_packages, setup
6
+ from setuptools.command.build_ext import build_ext
7
+ from pathlib import Path
8
+
9
+
10
+ def find_version(src_file_content: str):
11
+ # find macro SSRJSON_BENCHMARK_VERSION
12
+ prefix = "#define SSRJSON_BENCHMARK_VERSION"
13
+ for line in src_file_content.splitlines():
14
+ if line.startswith(prefix):
15
+ version = line[len(prefix) :].strip()[1:-1]
16
+ return version
17
+ raise RuntimeError("Cannot find SSRJSON_BENCHMARK_VERSION in source file")
18
+
19
+
20
+ with open("./src/benchmark.c", "r", encoding="utf-8") as f:
21
+ version_string = find_version(f.read())
22
+
23
+
24
+ class CMakeBuild(build_ext):
25
+ def run(self):
26
+ build_dir = os.path.abspath("build")
27
+ if not os.path.exists(build_dir):
28
+ os.makedirs(build_dir)
29
+ cmake_cmd = [
30
+ "cmake",
31
+ "-DCMAKE_BUILD_TYPE=Release",
32
+ ".",
33
+ "-B",
34
+ "build",
35
+ ]
36
+ subprocess.check_call(cmake_cmd)
37
+
38
+ if os.name == "nt":
39
+ build_cmd = ["cmake", "--build", "build", "--config", "Release"]
40
+ else:
41
+ build_cmd = ["cmake", "--build", "build"]
42
+ subprocess.check_call(build_cmd)
43
+
44
+ if os.name == "nt":
45
+ built_filename = "Release/_ssrjson_benchmark.dll"
46
+ target_filename = "_ssrjson_benchmark.pyd"
47
+ else:
48
+ built_filename = "_ssrjson_benchmark.so"
49
+ target_filename = built_filename
50
+
51
+ built_path = os.path.join(build_dir, built_filename)
52
+ if not os.path.exists(built_path):
53
+ raise RuntimeError(f"Built library not found: {built_path}")
54
+
55
+ target_dir = self.build_lib + "/ssrjson_benchmark"
56
+ if not os.path.exists(target_dir):
57
+ os.makedirs(target_dir)
58
+
59
+ target_path = os.path.join(target_dir, target_filename)
60
+ self.announce(f"Copying {built_path} to {target_path}")
61
+ print(f"Copying {built_path} to {target_path}")
62
+ shutil.copyfile(built_path, target_path)
63
+
64
+
65
+ setup(
66
+ name="ssrjson_benchmark",
67
+ version=version_string,
68
+ description="Benchmark for ssrJSON",
69
+ long_description=Path("README.md").read_text(encoding="utf-8"),
70
+ long_description_content_type="text/markdown",
71
+ ext_modules=[
72
+ Extension(
73
+ "_ssrjson_benchmark",
74
+ sources=["src/benchmark.c"],
75
+ language="c",
76
+ )
77
+ ],
78
+ packages=["ssrjson_benchmark", "ssrjson_benchmark._files"],
79
+ package_dir={"": "src"},
80
+ package_data={
81
+ "ssrjson_benchmark": ["template.md"],
82
+ "ssrjson_benchmark._files": ["*.json"],
83
+ },
84
+ include_package_data=True,
85
+ install_requires=[
86
+ "ssrjson",
87
+ "orjson",
88
+ "matplotlib",
89
+ ],
90
+ extras_require={
91
+ "all": [
92
+ "svglib",
93
+ "reportlab",
94
+ "py-cpuinfo",
95
+ ],
96
+ },
97
+ cmdclass={
98
+ "build_ext": CMakeBuild,
99
+ },
100
+ )
@@ -23,7 +23,7 @@
23
23
  #include <Python.h>
24
24
  #include <stdbool.h>
25
25
 
26
- #define SSRJSON_BENCHMARK_VERSION "0.0.1"
26
+ #define SSRJSON_BENCHMARK_VERSION "0.0.1b0"
27
27
 
28
28
  /** compiler builtin check (since gcc 10.0, clang 2.6, icc 2021) */
29
29
  #ifndef has_builtin
@@ -319,7 +319,7 @@ static PyMethodDef ssrjson_benchmark_methods[] = {
319
319
 
320
320
  static struct PyModuleDef moduledef = {
321
321
  PyModuleDef_HEAD_INIT,
322
- "ssrjson_benchmark", /* m_name */
322
+ "_ssrjson_benchmark", /* m_name */
323
323
  0, /* m_doc */
324
324
  0, /* m_size */
325
325
  ssrjson_benchmark_methods, /* m_methods */
@@ -329,7 +329,7 @@ static struct PyModuleDef moduledef = {
329
329
  NULL /* m_free */
330
330
  };
331
331
 
332
- PyMODINIT_FUNC PyInit_ssrjson_benchmark(void) {
332
+ PyMODINIT_FUNC PyInit__ssrjson_benchmark(void) {
333
333
  PyObject *module;
334
334
  // check if module already exists
335
335
  if ((module = PyState_FindModule(&moduledef)) != NULL) {
@@ -0,0 +1,15 @@
1
+ from .benchmark_main import (
2
+ run_benchmark,
3
+ generate_report_markdown,
4
+ generate_report,
5
+ run_benchmark_default,
6
+ )
7
+ from ._ssrjson_benchmark import __version__
8
+
9
+ __all__ = [
10
+ "run_benchmark",
11
+ "generate_report_markdown",
12
+ "generate_report",
13
+ "run_benchmark_default",
14
+ "__version__",
15
+ ]
@@ -0,0 +1,54 @@
1
+ import argparse
2
+ import json
3
+ import os
4
+ from ssrjson_benchmark import (
5
+ run_benchmark,
6
+ generate_report_markdown,
7
+ generate_report,
8
+ )
9
+
10
+
11
+ def main():
12
+ parser = argparse.ArgumentParser()
13
+
14
+ parser.add_argument(
15
+ "-f", "--file", help="record JSON file", required=False, default=None
16
+ )
17
+ parser.add_argument(
18
+ "-m",
19
+ "--markdown",
20
+ help="Generate markdown report",
21
+ required=False,
22
+ action="store_true",
23
+ )
24
+ parser.add_argument(
25
+ "--process-bytes",
26
+ help="Total process bytes per test, default 1e8",
27
+ required=False,
28
+ default=1e8,
29
+ type=int,
30
+ )
31
+ parser.add_argument(
32
+ "--out-dir",
33
+ help="Output directory for reports",
34
+ required=False,
35
+ default=os.getcwd(),
36
+ )
37
+ args = parser.parse_args()
38
+
39
+ if args.file:
40
+ with open(args.file, "r") as f:
41
+ j = json.load(f)
42
+ file = args.file.split("/")[-1]
43
+ else:
44
+ j, file = run_benchmark(args.process_bytes)
45
+ file = file.split("/")[-1]
46
+
47
+ if args.markdown:
48
+ generate_report_markdown(j, file, args.out_dir)
49
+ else:
50
+ generate_report(j, file, args.out_dir)
51
+
52
+
53
+ if __name__ == "__main__":
54
+ main()