Debian Codegraph @

debian/missing-sources/glib/benches/gstring.rs

raw
1 use criterion::{Criterion, criterion_group, criterion_main};
2 use glib::IntoGStr;
3 use std::hint::black_box;
4
5 pub fn str_into_gstr(c: &mut Criterion) {
6 c.bench_function("str as IntoGStr", |b| {
7 b.iter(|| {
8 "abcdefg".run_with_gstr(|g| {
9 black_box(g);
10 })
11 })
12 });
13 }
14
15 pub fn string_into_gstr(c: &mut Criterion) {
16 c.bench_function("String as IntoGStr", |b| {
17 b.iter(|| {
18 let mut s = String::from("abcdefg");
19 s.shrink_to_fit();
20 assert_eq!(s.capacity(), s.len());
21 s.run_with_gstr(|g| {
22 black_box(g);
23 })
24 })
25 });
26 }
27
28 pub fn string_with_capacity_into_gstr(c: &mut Criterion) {
29 c.bench_function("String::with_capacity as IntoGStr", |b| {
30 b.iter(|| {
31 let mut s = String::with_capacity(100);
32 s.push_str("abcdefg");
33 assert!(s.capacity() > s.len());
34 s.run_with_gstr(|g| {
35 black_box(g);
36 })
37 })
38 });
39 }
40
41 criterion_group!(
42 benches,
43 str_into_gstr,
44 string_into_gstr,
45 string_with_capacity_into_gstr
46 );
47 criterion_main!(benches);