Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python benchmarks #104

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ jobs:
env:
RUST_BACKTRACE: 1

- run: python crates/jiter-python/bench.py
env:
FAST: 1

- run: coverage-prepare lcov $(python -c 'import jiter.jiter;print(jiter.jiter.__file__)')

- uses: codecov/codecov-action@v4
Expand Down
23 changes: 15 additions & 8 deletions crates/jiter-python/bench.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import argparse
import os
import timeit
from pathlib import Path

import json

FAST = bool(os.getenv('FAST'))
THIS_DIR = Path(__file__).parent

cases = [
("medium_response", Path("../jiter/benches/medium_response.json").read_bytes()),
("medium_response", (THIS_DIR / "../jiter/benches/medium_response.json").read_bytes()),
(
"massive_ints_array",
Path("../jiter/benches/massive_ints_array.json").read_bytes(),
(THIS_DIR / "../jiter/benches/massive_ints_array.json").read_bytes(),
),
("array_short_strings", "[{}]".format(", ".join('"123"' for _ in range(100_000)))),
(
Expand All @@ -31,10 +35,13 @@ def run_bench(func, d):
timer = timeit.Timer(
"func(json_data)", setup="", globals={"func": func, "json_data": d}
)
n, t = timer.autorange()
iter_time = t / n
# print(f'{func.__module__}.{func.__name__}', iter_time)
return iter_time
if FAST:
return timer.timeit(1)
else:
n, t = timer.autorange()
iter_time = t / n
# print(f'{func.__module__}.{func.__name__}', iter_time)
return iter_time


def setup_orjson():
Expand All @@ -46,13 +53,13 @@ def setup_orjson():
def setup_jiter_cache():
import jiter

return lambda data: jiter.from_json(data, cache_strings=True)
return lambda data: jiter.from_json(data, cache_mode=True)


def setup_jiter():
import jiter

return lambda data: jiter.from_json(data, cache_strings=False)
return lambda data: jiter.from_json(data, cache_mode=False)


def setup_ujson():
Expand Down
2 changes: 2 additions & 0 deletions crates/jiter-python/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pytest
pytest-pretty
dirty_equals
orjson
ujson
Loading