Skip to content

Commit

Permalink
bench
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jul 14, 2024
1 parent a765143 commit 7b59bdc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/swc_allocator/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern crate swc_malloc;

use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};
use swc_allocator::Allocator;

fn bench_alloc(c: &mut Criterion) {
fn direct_alloc(b: &mut Bencher, times: usize) {
Expand All @@ -12,9 +13,25 @@ fn bench_alloc(c: &mut Criterion) {
})
}

c.bench_function("common/allocator/alloc/1000_000_000", |b| {
fn direct_alloc_in_scope(b: &mut Bencher, times: usize) {
b.iter(|| {
let allocator = Allocator::default();

allocator.scope(|| {
for _ in 0..times {
let _: swc_allocator::boxed::Box<usize> =
black_box(swc_allocator::boxed::Box::new(black_box(1234)));
}
});
})
}

c.bench_function("common/allocator/alloc/no-scope/1000_000_000", |b| {
direct_alloc(b, 1000 * 1000 * 1000)
});
c.bench_function("common/allocator/alloc/scoped/1000_000_000", |b| {
direct_alloc_in_scope(b, 1000 * 1000 * 1000)
});
}

criterion_group!(benches, bench_alloc);
Expand Down

0 comments on commit 7b59bdc

Please sign in to comment.