This is an automated email from the ASF dual-hosted git repository.

tisonkun pushed a commit to branch codex/kll-api-and-performance
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git

commit 8b5eed1b07c2fd81f4e096ded97ff084b38d619d
Author: tison <[email protected]>
AuthorDate: Wed Sep 2 12:17:30 2026 +0800

    bench(kll): cover update query merge and serde
---
 benchmarks/Cargo.toml                  |  2 +-
 benchmarks/{main.rs => kll/merge.rs}   | 25 +++++++++++------
 benchmarks/{main.rs => kll/mod.rs}     | 17 ++++--------
 benchmarks/kll/query.rs                | 49 ++++++++++++++++++++++++++++++++++
 benchmarks/{main.rs => kll/serde.rs}   | 27 +++++++++++++------
 benchmarks/{main.rs => kll/support.rs} | 29 ++++++++++++++------
 benchmarks/{main.rs => kll/update.rs}  | 20 +++++++-------
 benchmarks/main.rs                     |  1 +
 8 files changed, 124 insertions(+), 46 deletions(-)

diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml
index 115320a..3bbbda5 100644
--- a/benchmarks/Cargo.toml
+++ b/benchmarks/Cargo.toml
@@ -23,7 +23,7 @@ edition.workspace = true
 rust-version.workspace = true
 
 [dev-dependencies]
-datasketches = { workspace = true, features = ["cpc", "req", "tdigest"] }
+datasketches = { workspace = true, features = ["cpc", "kll", "req", "tdigest"] 
}
 divan = { workspace = true }
 rand = { workspace = true }
 
diff --git a/benchmarks/main.rs b/benchmarks/kll/merge.rs
similarity index 59%
copy from benchmarks/main.rs
copy to benchmarks/kll/merge.rs
index 4f8ed78..c35a1af 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/kll/merge.rs
@@ -15,15 +15,24 @@
 // 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 req;
-mod tdigest;
+#[divan::bench]
+fn merge(bencher: Bencher) {
+    let values = values(200_000);
+    let left = build_sketch(&values[..100_000]);
+    let right = build_sketch(&values[100_000..]);
 
-fn main() {
-    divan::main();
+    bencher
+        .counter(ItemsCount::new(values.len()))
+        .with_inputs(|| left.clone())
+        .bench_local_values(|mut left| {
+            left.merge(black_box(&right)).unwrap();
+            black_box(left)
+        });
 }
diff --git a/benchmarks/main.rs b/benchmarks/kll/mod.rs
similarity index 82%
copy from benchmarks/main.rs
copy to benchmarks/kll/mod.rs
index 4f8ed78..4ff11ff 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/kll/mod.rs
@@ -15,15 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use divan::AllocProfiler;
-
-#[global_allocator]
-static ALLOC: AllocProfiler = AllocProfiler::system();
-
-mod cpc;
-mod req;
-mod tdigest;
-
-fn main() {
-    divan::main();
-}
+mod merge;
+mod query;
+mod serde;
+mod support;
+mod update;
diff --git a/benchmarks/kll/query.rs b/benchmarks/kll/query.rs
new file mode 100644
index 0000000..3e50112
--- /dev/null
+++ b/benchmarks/kll/query.rs
@@ -0,0 +1,49 @@
+// 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::kll::SearchCriteria;
+use divan::Bencher;
+use divan::black_box;
+
+use super::support::prepared_sketch;
+
+#[divan::bench]
+fn rank(bencher: Bencher) {
+    let sketch = prepared_sketch();
+    bencher
+        .bench_local(|| black_box(&sketch).rank(black_box(&500_000.0), 
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));
+}
+
+#[divan::bench]
+fn sorted_view_quantile(bencher: Bencher) {
+    let view = prepared_sketch().sorted_view();
+    bencher.bench_local(|| black_box(&view).quantile(black_box(0.5), 
SearchCriteria::Inclusive));
+}
+
+#[divan::bench]
+fn batch_quantiles(bencher: Bencher) {
+    let sketch = prepared_sketch();
+    let ranks = [0.01, 0.1, 0.25, 0.5, 0.75, 0.9, 0.99];
+    bencher
+        .bench_local(|| black_box(&sketch).quantiles(black_box(&ranks), 
SearchCriteria::Inclusive));
+}
diff --git a/benchmarks/main.rs b/benchmarks/kll/serde.rs
similarity index 56%
copy from benchmarks/main.rs
copy to benchmarks/kll/serde.rs
index 4f8ed78..28169af 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/kll/serde.rs
@@ -15,15 +15,26 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use divan::AllocProfiler;
+use datasketches::kll::KllSketch;
+use divan::Bencher;
+use divan::black_box;
+use divan::counter::BytesCount;
 
-#[global_allocator]
-static ALLOC: AllocProfiler = AllocProfiler::system();
+use super::support::prepared_sketch;
 
-mod cpc;
-mod req;
-mod tdigest;
+#[divan::bench]
+fn serialize(bencher: Bencher) {
+    let sketch = prepared_sketch();
+    let bytes = sketch.serialize();
+    bencher
+        .counter(BytesCount::new(bytes.len()))
+        .bench_local(|| black_box(&sketch).serialize());
+}
 
-fn main() {
-    divan::main();
+#[divan::bench]
+fn deserialize(bencher: Bencher) {
+    let bytes = prepared_sketch().serialize();
+    bencher
+        .counter(BytesCount::new(bytes.len()))
+        .bench_local(|| 
KllSketch::<f64>::deserialize(black_box(&bytes)).unwrap());
 }
diff --git a/benchmarks/main.rs b/benchmarks/kll/support.rs
similarity index 57%
copy from benchmarks/main.rs
copy to benchmarks/kll/support.rs
index 4f8ed78..5f756ea 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/kll/support.rs
@@ -15,15 +15,28 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use divan::AllocProfiler;
+use datasketches::kll::KllSketch;
+use rand::RngExt;
+use rand::SeedableRng;
+use rand::rngs::StdRng;
 
-#[global_allocator]
-static ALLOC: AllocProfiler = AllocProfiler::system();
+pub(super) const DEFAULT_K: u16 = 200;
 
-mod cpc;
-mod req;
-mod tdigest;
+pub(super) fn values(len: usize) -> Vec<f64> {
+    let mut rng = StdRng::seed_from_u64(42);
+    (0..len)
+        .map(|_| rng.random_range(0.0..1_000_000.0))
+        .collect()
+}
+
+pub(super) fn build_sketch(values: &[f64]) -> KllSketch<f64> {
+    let mut sketch = KllSketch::new(DEFAULT_K).unwrap();
+    for &value in values {
+        sketch.update(value);
+    }
+    sketch
+}
 
-fn main() {
-    divan::main();
+pub(super) fn prepared_sketch() -> KllSketch<f64> {
+    build_sketch(&values(100_000))
 }
diff --git a/benchmarks/main.rs b/benchmarks/kll/update.rs
similarity index 68%
copy from benchmarks/main.rs
copy to benchmarks/kll/update.rs
index 4f8ed78..6a3c865 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/kll/update.rs
@@ -15,15 +15,17 @@
 // 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 req;
-mod tdigest;
-
-fn main() {
-    divan::main();
+#[divan::bench(args = [1_000, 10_000, 100_000])]
+fn update(bencher: Bencher, len: usize) {
+    let values = values(len);
+    bencher
+        .counter(ItemsCount::new(len))
+        .bench_local(|| build_sketch(black_box(&values)));
 }
diff --git a/benchmarks/main.rs b/benchmarks/main.rs
index 4f8ed78..11c9962 100644
--- a/benchmarks/main.rs
+++ b/benchmarks/main.rs
@@ -21,6 +21,7 @@ use divan::AllocProfiler;
 static ALLOC: AllocProfiler = AllocProfiler::system();
 
 mod cpc;
+mod kll;
 mod req;
 mod tdigest;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to