This is an automated email from the ASF dual-hosted git repository.
tisonkun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 5241150 test(req): add REQ sketch benchmarks (#251)
5241150 is described below
commit 524115071046b48011365571fab4cd21b6bacc01
Author: Patrick McGleenon <[email protected]>
AuthorDate: Mon Aug 31 10:19:31 2026 +0200
test(req): add REQ sketch benchmarks (#251)
---
Cargo.lock | 1 +
benchmarks/Cargo.toml | 3 ++-
benchmarks/main.rs | 1 +
benchmarks/{main.rs => req/mod.rs} | 14 +++-------
benchmarks/req/query.rs | 48 +++++++++++++++++++++++++++++++++++
benchmarks/req/support.rs | 46 +++++++++++++++++++++++++++++++++
benchmarks/{main.rs => req/update.rs} | 18 ++++++++-----
7 files changed, 112 insertions(+), 19 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 87ec3e3..189dc8e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -85,6 +85,7 @@ version = "0.0.0"
dependencies = [
"datasketches",
"divan",
+ "rand",
]
[[package]]
diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml
index 254de06..115320a 100644
--- a/benchmarks/Cargo.toml
+++ b/benchmarks/Cargo.toml
@@ -23,8 +23,9 @@ edition.workspace = true
rust-version.workspace = true
[dev-dependencies]
-datasketches = { workspace = true, features = ["cpc", "tdigest"] }
+datasketches = { workspace = true, features = ["cpc", "req", "tdigest"] }
divan = { workspace = true }
+rand = { workspace = true }
[[bench]]
harness = false
diff --git a/benchmarks/main.rs b/benchmarks/main.rs
index b89eebc..4f8ed78 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/main.rs
@@ -21,6 +21,7 @@ use divan::AllocProfiler;
static ALLOC: AllocProfiler = AllocProfiler::system();
mod cpc;
+mod req;
mod tdigest;
fn main() {
diff --git a/benchmarks/main.rs b/benchmarks/req/mod.rs
similarity index 83%
copy from benchmarks/main.rs
copy to benchmarks/req/mod.rs
index b89eebc..900ddb9 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/req/mod.rs
@@ -15,14 +15,6 @@
// specific language governing permissions and limitations
// under the License.
-use divan::AllocProfiler;
-
-#[global_allocator]
-static ALLOC: AllocProfiler = AllocProfiler::system();
-
-mod cpc;
-mod tdigest;
-
-fn main() {
- divan::main();
-}
+mod query;
+mod support;
+mod update;
diff --git a/benchmarks/req/query.rs b/benchmarks/req/query.rs
new file mode 100644
index 0000000..916f5e8
--- /dev/null
+++ b/benchmarks/req/query.rs
@@ -0,0 +1,48 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datasketches::req::ReqFloat;
+use datasketches::req::SearchCriteria;
+use divan::Bencher;
+use divan::black_box;
+
+use super::support::prepared_sketch;
+
+#[divan::bench]
+fn rank(bencher: Bencher) {
+ let sketch = prepared_sketch();
+ let item = ReqFloat::<f64>::new(500_000.0).unwrap();
+
+ bencher.bench_local(|| black_box(&sketch).rank(black_box(&item),
SearchCriteria::Inclusive));
+}
+
+#[divan::bench]
+fn quantile(bencher: Bencher) {
+ let sketch = prepared_sketch();
+
+ bencher.bench_local(|| black_box(&sketch).quantile(black_box(0.5),
SearchCriteria::Inclusive));
+}
+
+// Intended pattern for repeated queries: build the view once, query it many
+// times. Contrast against `quantile`, which rebuilds the view on every call.
+#[divan::bench]
+fn sorted_view_quantile(bencher: Bencher) {
+ let sketch = prepared_sketch();
+ let view = sketch.sorted_view();
+
+ bencher.bench_local(|| black_box(&view).quantile(black_box(0.5),
SearchCriteria::Inclusive));
+}
diff --git a/benchmarks/req/support.rs b/benchmarks/req/support.rs
new file mode 100644
index 0000000..34f6c29
--- /dev/null
+++ b/benchmarks/req/support.rs
@@ -0,0 +1,46 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use datasketches::req::RankAccuracy;
+use datasketches::req::ReqFloat;
+use datasketches::req::ReqSketch;
+use rand::RngExt;
+use rand::SeedableRng;
+use rand::rngs::StdRng;
+
+pub(super) const DEFAULT_K: u16 = 12;
+
+pub(super) fn prepared_sketch() -> ReqSketch<ReqFloat<f64>> {
+ build_sketch(&values(100_000))
+}
+
+pub(super) fn build_sketch(values: &[ReqFloat<f64>]) ->
ReqSketch<ReqFloat<f64>> {
+ let mut sketch = ReqSketch::new(DEFAULT_K,
RankAccuracy::HighRank).unwrap();
+ for value in values {
+ sketch.update(*value);
+ }
+ sketch
+}
+
+/// Uniform values in `[0, 1_000_000)`, generated with a fixed seed for
+/// reproducible benchmarks.
+pub(super) fn values(len: usize) -> Vec<ReqFloat<f64>> {
+ let mut rng = StdRng::seed_from_u64(42);
+ (0..len)
+ .map(|_|
ReqFloat::<f64>::new(rng.random_range(0.0..1_000_000.0)).unwrap())
+ .collect()
+}
diff --git a/benchmarks/main.rs b/benchmarks/req/update.rs
similarity index 68%
copy from benchmarks/main.rs
copy to benchmarks/req/update.rs
index b89eebc..5d8c62a 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/req/update.rs
@@ -15,14 +15,18 @@
// specific language governing permissions and limitations
// under the License.
-use divan::AllocProfiler;
+use divan::Bencher;
+use divan::black_box;
+use divan::counter::ItemsCount;
-#[global_allocator]
-static ALLOC: AllocProfiler = AllocProfiler::system();
+use super::support::build_sketch;
+use super::support::values;
-mod cpc;
-mod tdigest;
+#[divan::bench(args = [1_000, 10_000, 100_000])]
+fn update(bencher: Bencher, len: usize) {
+ let values = values(len);
-fn main() {
- divan::main();
+ bencher
+ .counter(ItemsCount::new(len))
+ .bench_local(|| build_sketch(black_box(&values)));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]