diff --git a/lib/benches/store.rs b/lib/benches/store.rs index 569821f8..414dab6e 100644 --- a/lib/benches/store.rs +++ b/lib/benches/store.rs @@ -161,7 +161,55 @@ fn run_operation(store: &Store, operations: &[Operation]) { } } -criterion_group!(store, store_query_and_update, store_load); +fn sparql_parsing(c: &mut Criterion) { + let mut data = Vec::new(); + read_data("explore-1000.nt.zst") + .read_to_end(&mut data) + .unwrap(); + + let operations = read_data("mix-exploreAndUpdate-1000.tsv.zst") + .lines() + .map(|l| { + let l = l.unwrap(); + let mut parts = l.trim().split('\t'); + let kind = parts.next().unwrap(); + let operation = parts.next().unwrap(); + match kind { + "query" => RawOperation::Query(operation.to_string()), + "update" => RawOperation::Update(operation.to_string()), + _ => panic!("Unexpected operation kind {kind}"), + } + }) + .collect::>(); + + let mut group = c.benchmark_group("sparql parsing"); + group.sample_size(10); + group.throughput(Throughput::Bytes( + operations + .iter() + .map(|o| match o { + RawOperation::Query(q) => q.len(), + RawOperation::Update(u) => u.len(), + }) + .sum::() as u64, + )); + group.bench_function("BSBM query and update set", |b| { + b.iter(|| { + for operation in &operations { + match operation { + RawOperation::Query(q) => { + Query::parse(q, None).unwrap(); + } + RawOperation::Update(u) => { + Update::parse(u, None).unwrap(); + } + } + } + }) + }); +} + +criterion_group!(store, sparql_parsing, store_query_and_update, store_load); criterion_main!(store); @@ -183,6 +231,12 @@ fn read_data(file: &str) -> impl BufRead { BufReader::new(zstd::Decoder::new(File::open(file).unwrap()).unwrap()) } +#[derive(Clone)] +enum RawOperation { + Query(String), + Update(String), +} + #[allow(clippy::large_enum_variant)] #[derive(Clone)] enum Operation { diff --git a/testsuite/Cargo.toml b/testsuite/Cargo.toml index a8165d86..e27113cf 100644 --- a/testsuite/Cargo.toml +++ b/testsuite/Cargo.toml @@ -20,7 +20,3 @@ text-diff = "0.4" [dev-dependencies] criterion = "0.4" - -[[bench]] -name = "sparql_query" -harness = false \ No newline at end of file diff --git a/testsuite/benches/sparql_query.rs b/testsuite/benches/sparql_query.rs deleted file mode 100644 index 6127e1f0..00000000 --- a/testsuite/benches/sparql_query.rs +++ /dev/null @@ -1,35 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; -use oxigraph::sparql::*; -use oxigraph_testsuite::files::read_file_to_string; -use oxigraph_testsuite::manifest::TestManifest; - -criterion_group!(sparql, sparql_w3c_syntax_bench); - -criterion_main!(sparql); - -fn sparql_w3c_syntax_bench(c: &mut Criterion) { - let manifest_urls = vec![ - "https://w3c.github.io/rdf-tests/sparql/sparql10/manifest-syntax.ttl", - "https://w3c.github.io/rdf-tests/sparql/sparql11/manifest-sparql11-query.ttl", - ]; - let queries: Vec<_> = TestManifest::new(manifest_urls) - .flat_map(|test| { - let test = test.unwrap(); - if test.kind == "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#PositiveSyntaxTest" - || test.kind - == "http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#PositiveSyntaxTest11" { - test.action.map(|query| (read_file_to_string(&query).unwrap(), query)) - } else { - None - } - }) - .collect(); - - c.bench_function("query parser", |b| { - b.iter(|| { - for (query, base) in &queries { - Query::parse(query, Some(base)).unwrap(); - } - }) - }); -}