|
1 | 1 | /* |
2 | 2 | The benchmark results: |
3 | 3 | criterion = "0.5.1" |
4 | | - rustc 1.82.0 (f6e511eec 2024-10-15) |
5 | | - OS: Ubuntu 22.04.3 LTS (5.15.167.4-microsoft-standard-WSL2) |
6 | | - Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs, |
| 4 | + rustc 1.83.0 (90b35a623 2024-11-26) |
| 5 | + OS: Ubuntu 22.04.4 LTS (5.15.167.4-microsoft-standard-WSL2) |
| 6 | + Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz 2.79 GHz |
7 | 7 | RAM: 64.0 GB |
8 | | - | Test | Average time| |
9 | | - |--------------------------------|-------------| |
10 | | - | Counter_Add_Sorted | 172 ns | |
11 | | - | Counter_Add_Unsorted | 183 ns | |
12 | | - | Counter_Overflow | 562 ns | |
13 | | - | ThreadLocal_Random_Generator_5 | 37 ns | |
| 8 | + | Test | Average time| |
| 9 | + |-------------------------------------------------------|-------------| |
| 10 | + | Counter_Add_Sorted | 160 ns | |
| 11 | + | Counter_Add_Unsorted | 164 ns | |
| 12 | + | Counter_Add_Sorted_With_Non_Static_Values | 439 ns | |
| 13 | + | Counter_Overflow | 562 ns | |
| 14 | + | ThreadLocal_Random_Generator_5 | 37 ns | |
14 | 15 | */ |
15 | 16 |
|
16 | 17 | use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; |
@@ -51,6 +52,7 @@ fn create_counter(name: &'static str) -> Counter<u64> { |
51 | 52 | fn criterion_benchmark(c: &mut Criterion) { |
52 | 53 | counter_add_sorted(c); |
53 | 54 | counter_add_unsorted(c); |
| 55 | + counter_add_sorted_with_non_static_values(c); |
54 | 56 | counter_overflow(c); |
55 | 57 | random_generator(c); |
56 | 58 | } |
@@ -127,6 +129,68 @@ fn counter_add_unsorted(c: &mut Criterion) { |
127 | 129 | }); |
128 | 130 | } |
129 | 131 |
|
| 132 | +fn counter_add_sorted_with_non_static_values(c: &mut Criterion) { |
| 133 | + let counter = create_counter("Counter_Add_Sorted_With_Non_Static_Values"); |
| 134 | + c.bench_function("Counter_Add_Sorted_With_Non_Static_Values", |b| { |
| 135 | + b.iter_batched( |
| 136 | + || { |
| 137 | + ( |
| 138 | + [ |
| 139 | + "value1".to_owned(), |
| 140 | + "value2".to_owned(), |
| 141 | + "value3".to_owned(), |
| 142 | + "value4".to_owned(), |
| 143 | + "value5".to_owned(), |
| 144 | + "value6".to_owned(), |
| 145 | + "value7".to_owned(), |
| 146 | + "value8".to_owned(), |
| 147 | + "value9".to_owned(), |
| 148 | + "value10".to_owned(), |
| 149 | + ], |
| 150 | + // 4*4*10*10 = 1600 time series. |
| 151 | + CURRENT_RNG.with(|rng| { |
| 152 | + let mut rng = rng.borrow_mut(); |
| 153 | + [ |
| 154 | + rng.gen_range(0..4), |
| 155 | + rng.gen_range(0..4), |
| 156 | + rng.gen_range(0..10), |
| 157 | + rng.gen_range(0..10), |
| 158 | + ] |
| 159 | + }), |
| 160 | + ) |
| 161 | + }, |
| 162 | + |(attribute_values, rands)| { |
| 163 | + let index_first_attribute = rands[0]; |
| 164 | + let index_second_attribute = rands[1]; |
| 165 | + let index_third_attribute = rands[2]; |
| 166 | + let index_fourth_attribute = rands[3]; |
| 167 | + counter.add( |
| 168 | + 1, |
| 169 | + &[ |
| 170 | + KeyValue::new( |
| 171 | + "attribute1", |
| 172 | + attribute_values[index_first_attribute].as_str().to_owned(), |
| 173 | + ), |
| 174 | + KeyValue::new( |
| 175 | + "attribute2", |
| 176 | + attribute_values[index_second_attribute].as_str().to_owned(), |
| 177 | + ), |
| 178 | + KeyValue::new( |
| 179 | + "attribute3", |
| 180 | + attribute_values[index_third_attribute].as_str().to_owned(), |
| 181 | + ), |
| 182 | + KeyValue::new( |
| 183 | + "attribute4", |
| 184 | + attribute_values[index_fourth_attribute].as_str().to_owned(), |
| 185 | + ), |
| 186 | + ], |
| 187 | + ); |
| 188 | + }, |
| 189 | + BatchSize::SmallInput, |
| 190 | + ); |
| 191 | + }); |
| 192 | +} |
| 193 | + |
130 | 194 | fn counter_overflow(c: &mut Criterion) { |
131 | 195 | let counter = create_counter("Counter_Overflow"); |
132 | 196 | // Cause overflow. |
|
0 commit comments