Skip to content

Commit 81e95d2

Browse files
authored
Merge pull request #157 from faster-cpython/use-ujson
Use ujson
2 parents b3d4fe0 + 415871a commit 81e95d2

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

Diff for: bench_runner/hpt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
import io
2525
import functools
26-
import json
2726
from pathlib import Path
2827
from typing import Dict, Optional, Tuple
2928

3029

3130
import numpy as np
3231
from numpy.typing import NDArray
32+
import ujson
3333

3434

3535
ACC_MAXSU = 2
@@ -39,7 +39,7 @@ def load_from_json(
3939
json_path: Path,
4040
) -> Dict[str, NDArray[np.float64]]:
4141
with open(json_path) as fd:
42-
content = json.load(fd)
42+
content = ujson.load(fd)
4343

4444
return load_data(content)
4545

Diff for: bench_runner/plot.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import argparse
55
import datetime
6-
import json
76
from operator import attrgetter
87
from pathlib import Path
98
import re
@@ -13,6 +12,7 @@
1312
from matplotlib import pyplot as plt
1413
import matplotlib
1514
import numpy as np
15+
import ujson
1616

1717

1818
matplotlib.use("agg")
@@ -231,7 +231,7 @@ def get_comparison_value(ref, r, base):
231231
data_cache = output_filename.with_suffix(".json")
232232
if data_cache.is_file():
233233
with open(data_cache) as fd:
234-
data = json.load(fd)
234+
data = ujson.load(fd)
235235
else:
236236
data = {}
237237

@@ -317,7 +317,7 @@ def get_comparison_value(ref, r, base):
317317
plt.close()
318318

319319
with open(data_cache, "w") as fd:
320-
json.dump(data, fd, indent=2)
320+
ujson.dump(data, fd, indent=2)
321321

322322

323323
def flag_effect_plot(
@@ -348,7 +348,7 @@ def get_comparison_value(ref, r):
348348
data_cache = output_filename.with_suffix(".json")
349349
if data_cache.is_file():
350350
with open(data_cache) as fd:
351-
data = json.load(fd)
351+
data = ujson.load(fd)
352352
else:
353353
data = {}
354354

@@ -415,7 +415,7 @@ def get_comparison_value(ref, r):
415415
plt.close()
416416

417417
with open(data_cache, "w") as fd:
418-
json.dump(data, fd, indent=2)
418+
ujson.dump(data, fd, indent=2)
419419

420420

421421
if __name__ == "__main__":

Diff for: bench_runner/result.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from collections import defaultdict
66
import functools
7-
import json
87
from operator import itemgetter
98
from pathlib import Path
109
import re
@@ -17,6 +16,7 @@
1716
import numpy as np
1817
from packaging import version
1918
import pyperf
19+
import ujson
2020

2121

2222
from . import git
@@ -538,12 +538,12 @@ def contents(self) -> dict[str, Any]:
538538
if hasattr(self, "_full_contents"):
539539
return self._full_contents
540540

541-
with open(self.filename, "rb") as fd:
542-
self._full_contents = json.load(fd)
543-
544541
if hasattr(self, "_fast_contents"):
545542
del self._fast_contents
546543

544+
with open(self.filename, "rb") as fd:
545+
self._full_contents = ujson.load(fd)
546+
547547
return self._full_contents
548548

549549
@property

Diff for: bench_runner/scripts/remove_benchmark.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33

44
import argparse
5-
import json
65
from pathlib import Path
76

87

8+
import ujson
9+
10+
911
from bench_runner import result
1012
from bench_runner.scripts import generate_results
1113
from bench_runner import util
@@ -15,7 +17,7 @@ def remove_benchmark(
1517
filename: Path, remove: set[str], keep_hash: set[str], dry_run: bool
1618
):
1719
with open(filename) as fd:
18-
data = json.load(fd)
20+
data = ujson.load(fd)
1921

2022
if data["metadata"]["benchmark_hash"] in keep_hash:
2123
util.status("/")
@@ -36,7 +38,7 @@ def remove_benchmark(
3638

3739
if not dry_run:
3840
with open(filename, "w") as fd:
39-
json.dump(data, fd, indent=2)
41+
ujson.dump(data, fd, indent=2)
4042

4143

4244
def _main(benchmarks: list[str], keep_hash: list[str], dry_run: bool = False):

Diff for: bench_runner/scripts/run_benchmarks.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import argparse
55
import csv
6-
import json
76
import os
87
from operator import itemgetter
98
from pathlib import Path
@@ -15,6 +14,9 @@
1514
from typing import Iterable, Optional, Union
1615

1716

17+
import ujson
18+
19+
1820
from bench_runner import git
1921
from bench_runner.result import Result
2022
from bench_runner.table import md_link
@@ -104,7 +106,7 @@ def run_benchmarks(
104106
f"No benchmark file created at {BENCHMARK_JSON.resolve()}."
105107
)
106108
with open(BENCHMARK_JSON) as fd:
107-
contents = json.load(fd)
109+
contents = ujson.load(fd)
108110
if len(contents.get("benchmarks", [])) == 0:
109111
raise NoBenchmarkError("No benchmarks were run.")
110112

@@ -234,7 +236,7 @@ def update_metadata(
234236
run_id: Optional[str] = None,
235237
) -> None:
236238
with open(filename) as fd:
237-
content = json.load(fd)
239+
content = ujson.load(fd)
238240

239241
metadata = content.setdefault("metadata", {})
240242

@@ -250,7 +252,7 @@ def update_metadata(
250252
metadata["github_action_url"] = f"{GITHUB_URL}/actions/runs/{run_id}"
251253

252254
with open(filename, "w") as fd:
253-
json.dump(content, fd, indent=2)
255+
ujson.dump(content, fd, indent=2)
254256

255257

256258
def copy_to_directory(

Diff for: pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies = [
1919
"matplotlib==3.8.3",
2020
"pyperf>=2.6.0",
2121
"ruamel.yaml==0.18.6",
22+
"ujson==5.9.0",
2223
"wheel",
2324
]
2425
dynamic = ["version"]

0 commit comments

Comments
 (0)