Skip to content
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
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ ahash = "0.8.0"
smallvec = "1.11.0"
pyo3 = { version = "0.21.0-beta.0", default-features=false, features = ["num-bigint"], optional = true }
lexical-parse-float = { version = "0.8.5", features = ["format"] }
hashbrown = "0.14.3"

[features]
python = ["dep:pyo3"]
Expand Down
44 changes: 28 additions & 16 deletions benches/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ use std::io::Read;

use pyo3::Python;

use jiter::python_parse;
use jiter::{cache_clear, python_parse, StringCacheMode};

fn python_parse_numeric(bench: &mut Bencher) {
Python::with_gil(|py| {
cache_clear(py);
bench.iter(|| {
python_parse(
py,
br#" { "int": 1, "bigint": 123456789012345678901234567890, "float": 1.2} "#,
false,
true,
StringCacheMode::All,
false,
)
.unwrap()
Expand All @@ -24,64 +25,75 @@ fn python_parse_numeric(bench: &mut Bencher) {

fn python_parse_other(bench: &mut Bencher) {
Python::with_gil(|py| {
bench.iter(|| python_parse(py, br#"["string", true, false, null]"#, false, true, false).unwrap());
cache_clear(py);
bench.iter(|| {
python_parse(
py,
br#"["string", true, false, null]"#,
false,
StringCacheMode::All,
false,
)
.unwrap()
});
})
}

fn _python_parse_file(path: &str, bench: &mut Bencher, cache_strings: bool) {
fn _python_parse_file(path: &str, bench: &mut Bencher, cache_mode: StringCacheMode) {
let mut file = File::open(path).unwrap();
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
let json_data = contents.as_bytes();

Python::with_gil(|py| {
bench.iter(|| python_parse(py, json_data, false, cache_strings, false).unwrap());
cache_clear(py);
bench.iter(|| python_parse(py, json_data, false, cache_mode, false).unwrap());
})
}

fn python_parse_medium_response_not_cached(bench: &mut Bencher) {
_python_parse_file("./benches/medium_response.json", bench, false);
_python_parse_file("./benches/medium_response.json", bench, StringCacheMode::None);
}

fn python_parse_medium_response(bench: &mut Bencher) {
_python_parse_file("./benches/medium_response.json", bench, true);
_python_parse_file("./benches/medium_response.json", bench, StringCacheMode::All);
}

fn python_parse_true_object_not_cached(bench: &mut Bencher) {
_python_parse_file("./benches/true_object.json", bench, false);
_python_parse_file("./benches/true_object.json", bench, StringCacheMode::None);
}

fn python_parse_string_array_not_cached(bench: &mut Bencher) {
_python_parse_file("./benches/string_array.json", bench, false);
_python_parse_file("./benches/string_array.json", bench, StringCacheMode::None);
}

fn python_parse_string_array(bench: &mut Bencher) {
_python_parse_file("./benches/string_array.json", bench, true);
_python_parse_file("./benches/string_array.json", bench, StringCacheMode::All);
}

fn python_parse_x100_not_cached(bench: &mut Bencher) {
_python_parse_file("./benches/x100.json", bench, false);
_python_parse_file("./benches/x100.json", bench, StringCacheMode::None);
}

fn python_parse_x100(bench: &mut Bencher) {
_python_parse_file("./benches/x100.json", bench, true);
_python_parse_file("./benches/x100.json", bench, StringCacheMode::All);
}

fn python_parse_string_array_unique_not_cached(bench: &mut Bencher) {
_python_parse_file("./benches/string_array_unique.json", bench, false);
_python_parse_file("./benches/string_array_unique.json", bench, StringCacheMode::None);
}

fn python_parse_string_array_unique(bench: &mut Bencher) {
_python_parse_file("./benches/string_array_unique.json", bench, true);
_python_parse_file("./benches/string_array_unique.json", bench, StringCacheMode::All);
}

fn python_parse_true_object(bench: &mut Bencher) {
_python_parse_file("./benches/true_object.json", bench, true);
_python_parse_file("./benches/true_object.json", bench, StringCacheMode::All);
}

/// Note - caching strings should make no difference here
fn python_parse_true_array(bench: &mut Bencher) {
_python_parse_file("./benches/true_array.json", bench, true);
_python_parse_file("./benches/true_array.json", bench, StringCacheMode::All);
}

benchmark_group!(
Expand Down
Loading