Skip to content

Commit f71024f

Browse files
authored
Fix python benchmarks (#104)
1 parent be454d6 commit f71024f

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ jobs:
144144
env:
145145
RUST_BACKTRACE: 1
146146

147+
- run: python crates/jiter-python/bench.py
148+
env:
149+
FAST: 1
150+
147151
- run: coverage-prepare lcov $(python -c 'import jiter.jiter;print(jiter.jiter.__file__)')
148152

149153
- uses: codecov/codecov-action@v4

crates/jiter-python/bench.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import argparse
2+
import os
23
import timeit
34
from pathlib import Path
45

56
import json
67

8+
FAST = bool(os.getenv('FAST'))
9+
THIS_DIR = Path(__file__).parent
10+
711
cases = [
8-
("medium_response", Path("../jiter/benches/medium_response.json").read_bytes()),
12+
("medium_response", (THIS_DIR / "../jiter/benches/medium_response.json").read_bytes()),
913
(
1014
"massive_ints_array",
11-
Path("../jiter/benches/massive_ints_array.json").read_bytes(),
15+
(THIS_DIR / "../jiter/benches/massive_ints_array.json").read_bytes(),
1216
),
1317
("array_short_strings", "[{}]".format(", ".join('"123"' for _ in range(100_000)))),
1418
(
@@ -31,10 +35,13 @@ def run_bench(func, d):
3135
timer = timeit.Timer(
3236
"func(json_data)", setup="", globals={"func": func, "json_data": d}
3337
)
34-
n, t = timer.autorange()
35-
iter_time = t / n
36-
# print(f'{func.__module__}.{func.__name__}', iter_time)
37-
return iter_time
38+
if FAST:
39+
return timer.timeit(1)
40+
else:
41+
n, t = timer.autorange()
42+
iter_time = t / n
43+
# print(f'{func.__module__}.{func.__name__}', iter_time)
44+
return iter_time
3845

3946

4047
def setup_orjson():
@@ -46,13 +53,13 @@ def setup_orjson():
4653
def setup_jiter_cache():
4754
import jiter
4855

49-
return lambda data: jiter.from_json(data, cache_strings=True)
56+
return lambda data: jiter.from_json(data, cache_mode=True)
5057

5158

5259
def setup_jiter():
5360
import jiter
5461

55-
return lambda data: jiter.from_json(data, cache_strings=False)
62+
return lambda data: jiter.from_json(data, cache_mode=False)
5663

5764

5865
def setup_ujson():
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pytest
22
pytest-pretty
33
dirty_equals
4+
orjson
5+
ujson

0 commit comments

Comments
 (0)