|
7 | 7 | RAM: 64.0 GB |
8 | 8 | | Test | Average time| |
9 | 9 | |-------------------------------------------------------|-------------| |
10 | | - | Histogram_Record | 206.35 ns | |
11 | | - | Histogram_Record_With_Non_Static_Values | 483.58 ns | |
| 10 | + | Histogram_Record | 186.24 ns | |
| 11 | + | Histogram_Record_With_Non_Static_Values | 264.70 ns | |
12 | 12 |
|
13 | 13 | */ |
14 | 14 |
|
@@ -49,71 +49,64 @@ fn create_histogram(name: &'static str) -> Histogram<u64> { |
49 | 49 |
|
50 | 50 | fn criterion_benchmark(c: &mut Criterion) { |
51 | 51 | histogram_record(c); |
52 | | - histogram_record_with_non_static_values(c); |
| 52 | + |
| 53 | + let attribute_values = ["value1".to_owned(), "value2".to_owned(), "value3".to_owned(), "value4".to_owned(), "value5".to_owned(), "value6".to_owned(), "value7".to_owned(), "value8".to_owned(), "value9".to_owned(), "value10".to_owned()]; |
| 54 | + histogram_record_with_non_static_values(c, attribute_values); |
53 | 55 | } |
54 | 56 |
|
55 | 57 | fn histogram_record(c: &mut Criterion) { |
56 | 58 | let histogram = create_histogram("Histogram_Record"); |
57 | 59 | c.bench_function("Histogram_Record", |b| { |
58 | | - b.iter(|| { |
59 | | - // 4*4*10*10 = 1600 time series. |
60 | | - let rands = CURRENT_RNG.with(|rng| { |
61 | | - let mut rng = rng.borrow_mut(); |
62 | | - [ |
63 | | - rng.gen_range(0..4), |
64 | | - rng.gen_range(0..4), |
65 | | - rng.gen_range(0..10), |
66 | | - rng.gen_range(0..10), |
67 | | - ] |
68 | | - }); |
69 | | - let index_first_attribute = rands[0]; |
70 | | - let index_second_attribute = rands[1]; |
71 | | - let index_third_attribute = rands[2]; |
72 | | - let index_fourth_attribute = rands[3]; |
73 | | - histogram.record( |
74 | | - 1, |
75 | | - &[ |
76 | | - KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), |
77 | | - KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]), |
78 | | - KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]), |
79 | | - KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]), |
80 | | - ], |
81 | | - ); |
82 | | - }); |
| 60 | + b.iter_batched( |
| 61 | + || { |
| 62 | + // 4*4*10*10 = 1600 time series. |
| 63 | + CURRENT_RNG.with(|rng| { |
| 64 | + let mut rng = rng.borrow_mut(); |
| 65 | + [ |
| 66 | + rng.gen_range(0..4), |
| 67 | + rng.gen_range(0..4), |
| 68 | + rng.gen_range(0..10), |
| 69 | + rng.gen_range(0..10), |
| 70 | + ] |
| 71 | + }) |
| 72 | + }, |
| 73 | + |rands| { |
| 74 | + let index_first_attribute = rands[0]; |
| 75 | + let index_second_attribute = rands[1]; |
| 76 | + let index_third_attribute = rands[2]; |
| 77 | + let index_fourth_attribute = rands[3]; |
| 78 | + histogram.record( |
| 79 | + 1, |
| 80 | + &[ |
| 81 | + KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]), |
| 82 | + KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]), |
| 83 | + KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]), |
| 84 | + KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]), |
| 85 | + ], |
| 86 | + ); |
| 87 | + }, |
| 88 | + BatchSize::SmallInput, |
| 89 | + ); |
83 | 90 | }); |
84 | 91 | } |
85 | 92 |
|
86 | | -fn histogram_record_with_non_static_values(c: &mut Criterion) { |
| 93 | +fn histogram_record_with_non_static_values(c: &mut Criterion, attribute_values: [String; 10]) { |
87 | 94 | let histogram = create_histogram("Histogram_Record_With_Non_Static_Values"); |
88 | 95 | c.bench_function("Histogram_Record_With_Non_Static_Values", |b| { |
89 | 96 | b.iter_batched( |
90 | 97 | || { |
91 | | - ( |
| 98 | + // 4*4*10*10 = 1600 time series. |
| 99 | + CURRENT_RNG.with(|rng| { |
| 100 | + let mut rng = rng.borrow_mut(); |
92 | 101 | [ |
93 | | - "value1".to_owned(), |
94 | | - "value2".to_owned(), |
95 | | - "value3".to_owned(), |
96 | | - "value4".to_owned(), |
97 | | - "value5".to_owned(), |
98 | | - "value6".to_owned(), |
99 | | - "value7".to_owned(), |
100 | | - "value8".to_owned(), |
101 | | - "value9".to_owned(), |
102 | | - "value10".to_owned(), |
103 | | - ], |
104 | | - // 4*4*10*10 = 1600 time series. |
105 | | - CURRENT_RNG.with(|rng| { |
106 | | - let mut rng = rng.borrow_mut(); |
107 | | - [ |
108 | | - rng.gen_range(0..4), |
109 | | - rng.gen_range(0..4), |
110 | | - rng.gen_range(0..10), |
111 | | - rng.gen_range(0..10), |
112 | | - ] |
113 | | - }), |
114 | | - ) |
| 102 | + rng.gen_range(0..4), |
| 103 | + rng.gen_range(0..4), |
| 104 | + rng.gen_range(0..10), |
| 105 | + rng.gen_range(0..10), |
| 106 | + ] |
| 107 | + }) |
115 | 108 | }, |
116 | | - |(attribute_values, rands)| { |
| 109 | + |rands| { |
117 | 110 | let index_first_attribute = rands[0]; |
118 | 111 | let index_second_attribute = rands[1]; |
119 | 112 | let index_third_attribute = rands[2]; |
|
0 commit comments