|
1 | 1 | use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main};
|
2 |
| -use turbo_rcstr::RcStr; |
| 2 | +use turbo_rcstr::{RcStr, rcstr}; |
3 | 3 |
|
4 | 4 | // map has a fast-path if the Arc is uniquely owned
|
5 | 5 | fn bench_map(c: &mut Criterion) {
|
@@ -30,9 +30,26 @@ fn bench_map(c: &mut Criterion) {
|
30 | 30 | }
|
31 | 31 | }
|
32 | 32 |
|
| 33 | +/// Compare the performance of `from` and `rcstr!` |
| 34 | +fn bench_construct(c: &mut Criterion) { |
| 35 | + let mut g = c.benchmark_group("Rcstr::construct"); |
| 36 | + g.bench_with_input("rcstr!/small", "small", |f, _| { |
| 37 | + f.iter(|| rcstr!("hello")); |
| 38 | + }); |
| 39 | + g.bench_with_input("rcstr!/large", "large", |f, _| { |
| 40 | + f.iter(|| rcstr!("this is a long string that will take time to copy")); |
| 41 | +
88C0
}); |
| 42 | + |
| 43 | + g.bench_with_input("from/small", "small", |f, _| { |
| 44 | + f.iter(|| RcStr::from("hello")); |
| 45 | + }); |
| 46 | + g.bench_with_input("from/large", "large", |f, _| { |
| 47 | + f.iter(|| RcStr::from("this is a long string that will take time to copy")); |
| 48 | + }); |
| 49 | +} |
33 | 50 | criterion_group!(
|
34 | 51 | name = benches;
|
35 | 52 | config = Criterion::default();
|
36 |
| - targets = bench_map, |
| 53 | + targets = bench_map,bench_construct, |
37 | 54 | );
|
38 | 55 | criterion_main!(benches);
|
0 commit comments