-
Notifications
You must be signed in to change notification settings - Fork 0
/
alloc-vec-string.rs
57 lines (48 loc) · 1.48 KB
/
alloc-vec-string.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#![feature(trait_alias)]
#![feature(is_sorted)]
#![feature(extend_one)]
use cami::prelude::*;
use cami_benches::outish::{OutCollectionVecIndicator, OutIndicatorNonRefIndicator};
use cami_benches::rnd::MAX_ITEM_LEN;
use core::iter;
use criterion::{criterion_group, criterion_main, Criterion};
use fastrand::Rng;
pub fn bench_target(c: &mut Criterion) {
let mut rng = Rng::new();
type IdState = usize;
fn generate_item(rng: &mut Rng, total_length: &mut IdState) -> String {
let item_len = rng.usize(..MAX_ITEM_LEN);
let mut item = Vec::<char>::with_capacity(item_len);
item.extend(iter::repeat_with(|| rng.char(..)).take(item_len));
let mut string = String::with_capacity(4 * item_len);
string.extend(item.into_iter());
*total_length += string.len();
string
}
fn id_postfix(total_length: &IdState) -> String {
format!("Sum len: {total_length}.")
}
let mut total_length: IdState = 0; // NOT in chars, but in bytes.
lib_benches::shared::bench_vec_sort_bin_search::<
String,
String,
OutIndicatorNonRefIndicator,
OutCollectionVecIndicator,
Rng,
IdState,
>(
c,
&mut rng,
"string",
&mut total_length,
id_postfix,
generate_item,
|own| own.clone(),
);
}
criterion_group! {
name = benches;
config = lib_benches::criterionish::criterion_config();
targets = bench_target
}
criterion_main!(benches);