8000 Add a simple benchmark to demonstrate that the macro helps · vercel/next.js@ac7393d · GitHub
[go: up one dir, main page]

Skip to content

Commit ac7393d

Browse files
committed
Add a simple benchmark to demonstrate that the macro helps
1 parent 0e2b15f commit ac7393d

File tree

1 file changed

+19
-2
lines changed
  • turbopack/crates/turbo-rcstr/benches

1 file changed

+19
-2
lines changed

turbopack/crates/turbo-rcstr/benches/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main};
2-
use turbo_rcstr::RcStr;
2+
use turbo_rcstr::{RcStr, rcstr};
33

44
// map has a fast-path if the Arc is uniquely owned
55
fn bench_map(c: &mut Criterion) {
@@ -30,9 +30,26 @@ fn bench_map(c: &mut Criterion) {
3030
}
3131
}
3232

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+
}
3350
criterion_group!(
3451
name = benches;
3552
config = Criterion::default();
36-
targets = bench_map,
53+
targets = bench_map,bench_construct,
3754
);
3855
criterion_main!(benches);

0 commit comments

Comments
 (0)
0