2
2
// SPDX-FileCopyrightText: Copyright (c) 2025 owtotwo
3
3
// SPDX-License-Identifier: MIT
4
4
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.
5
27
use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
6
28
use micromap:: Map ;
7
29
@@ -15,6 +37,15 @@ pub fn insert_benchmark(c: &mut Criterion) {
15
37
} ) ;
16
38
} ) ;
17
39
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
+
18
49
c. bench_function ( "insert_different" , |b| {
19
50
const CAP : usize = 64 ;
20
51
let mut m: Map < usize , u64 , CAP > = Map :: new ( ) ;
@@ -25,7 +56,29 @@ pub fn insert_benchmark(c: &mut Criterion) {
25
56
} ) ;
26
57
} ) ;
27
58
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
+
28
69
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| {
29
82
const CAP : usize = 64 ;
30
83
let mut m: Map < usize , u64 , CAP > = Map :: new ( ) ;
31
84
b. iter ( || {
@@ -134,6 +187,6 @@ criterion_group!(
134
187
benches,
135
188
insert_benchmark,
136
189
length_benchmark,
137
- // insert_exist_kv_in_diff_slot
190
+ // insert_exist_kv_in_diff_slot // ignored for now
138
191
) ;
139
192
criterion_main ! ( benches) ;
0 commit comments