Skip to content

Commit 5385cdb

Browse files
authored
Merge pull request yegor256#271 from owtotwo/master
add some usage notes for benchmark file header
2 parents 0e03cbd + 5100b91 commit 5385cdb

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ run `cargo fmt` and `cargo clippy`.
113113
Also, before you start making changes, run benchmarks:
114114

115115
```bash
116-
rustup run nightly cargo bench
116+
cargo bench --bench bench
117117
```
118118

119119
Then, after the changes you make, run it again. Compare the results.

benches/bench.rs

+54-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22
// SPDX-FileCopyrightText: Copyright (c) 2025 owtotwo
33
// SPDX-License-Identifier: MIT
44

5+
/// Benchmark Usage:
6+
///
7+
/// `cargo bench --bench bench` will run all benchmarks in this file.
8+
/// ("--bench bench" for this file named "bench.rs", without this, the
9+
/// command `cargo bench` will run all benchmarks in the project.)
10+
///
11+
/// If you want to run a single benchmark, you can use the command
12+
/// `cargo bench -- insert_same`.
13+
///
14+
/// To filter benchmarks, use `cargo bench -- <filter>`, where <filter> is
15+
/// a regular expression matching the benchmark ID.
16+
///
17+
/// For example, running `cargo bench -- length` would only run benchmarks
18+
/// whose ID contains the string "length", such as "straight_length" and
19+
/// "fragmented_length".
20+
///
21+
/// You can use `cargo bench -- length --list` to see what benchmarks will
22+
/// be run.
23+
///
24+
/// While `cargo bench -- insert_.+` would match start with "insert_", such
25+
/// as "insert_same", "insert_same_ignore_return", "insert_and_remove" and
26+
/// so on.
527
use criterion::{black_box, criterion_group, criterion_main, Criterion};
628
use micromap::Map;
729

@@ -15,6 +37,15 @@ pub fn insert_benchmark(c: &mut Criterion) {
1537
});
1638
});
1739

40+
c.bench_function("insert_same_ignore_return", |b| {
41+
let mut m: Map<u64, u64, 64> = Map::new();
42+
b.iter(|| {
43+
for i in 0..1000 {
44+
let _ = m.insert(8, i);
45+
}
46+
});
47+
});
48+
1849
c.bench_function("insert_different", |b| {
1950
const CAP: usize = 64;
2051
let mut m: Map<usize, u64, CAP> = Map::new();
@@ -25,7 +56,29 @@ pub fn insert_benchmark(c: &mut Criterion) {
2556
});
2657
});
2758

59+
c.bench_function("insert_different_ignore_return", |b| {
60+
const CAP: usize = 64;
61+
let mut m: Map<usize, u64, CAP> = Map::new();
62+
b.iter(|| {
63+
for i in 0..CAP {
64+
let _ = m.insert(i, 256);
65+
}
66+
});
67+
});
68+
2869
c.bench_function("insert_and_remove", |b| {
70+
const CAP: usize = 64;
71+
let mut m: Map<usize, u64, CAP> = Map::new();
72+
b.iter(|| {
73+
for i in 0..CAP {
74+
let _ = m.insert(i, 256);
75+
let _ = m.remove(&i);
76+
black_box(m.len());
77+
}
78+
});
79+
});
80+
81+
c.bench_function("insert_and_remove_ignore_return", |b| {
2982
const CAP: usize = 64;
3083
let mut m: Map<usize, u64, CAP> = Map::new();
3184
b.iter(|| {
@@ -134,6 +187,6 @@ criterion_group!(
134187
benches,
135188
insert_benchmark,
136189
length_benchmark,
137-
// insert_exist_kv_in_diff_slot
190+
// insert_exist_kv_in_diff_slot // ignored for now
138191
);
139192
criterion_main!(benches);

0 commit comments

Comments
 (0)