Skip to content

Commit 6ea9f4f

Browse files
committed
add bench for MarkSweepGarbageCollector vs arena3 allocator
1 parent 0442fb6 commit 6ea9f4f

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

oscars/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ criterion = { version = "0.5", features = ["html_reports"] }
1515
boa_gc = { git = "https://github.com/boa-dev/boa", branch = "main" }
1616

1717
[[bench]]
18-
name = "oscars_vs_boa_gc"
18+
name = "oscars_arena3_vs_boa_gc"
1919
harness = false
2020
required-features = ["gc_allocator"]
2121

2222
[[bench]]
2323
name = "arena2_vs_arena3"
2424
harness = false
2525

26+
[[bench]]
27+
name = "mark_sweep_gc_vs_arena3"
28+
harness = false
29+
required-features = ["mark_sweep"]
30+
2631
[features]
2732
default = ["mark_sweep"]
2833
std = []
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
2+
use oscars::{Gc, MarkSweepGarbageCollector, cell::GcRefCell};
3+
4+
fn bench_alloc(c: &mut Criterion) {
5+
let mut group = c.benchmark_group("mark_sweep_gc/alloc");
6+
7+
for num_objects in [100, 500, 1000].iter() {
8+
group.bench_with_input(
9+
BenchmarkId::from_parameter(num_objects),
10+
num_objects,
11+
|b, &num_objects| {
12+
b.iter_batched(
13+
|| {
14+
MarkSweepGarbageCollector::default()
15+
.with_arena_size(65536)
16+
.with_heap_threshold(262144)
17+
},
18+
|collector| {
19+
let mut roots = Vec::new();
20+
for i in 0..num_objects {
21+
let root = Gc::new_in(GcRefCell::new(i), &collector);
22+
roots.push(root);
23+
}
24+
black_box(roots.len())
25+
},
26+
criterion::BatchSize::SmallInput,
27+
);
28+
},
29+
);
30+
}
31+
32+
group.finish();
33+
}
34+
35+
fn bench_collect(c: &mut Criterion) {
36+
let mut group = c.benchmark_group("mark_sweep_gc/collect");
37+
38+
for num_objects in [100, 500, 1000].iter() {
39+
group.bench_with_input(
40+
BenchmarkId::from_parameter(num_objects),
41+
num_objects,
42+
|b, &num_objects| {
43+
b.iter_batched(
44+
|| {
45+
let collector = MarkSweepGarbageCollector::default()
46+
.with_arena_size(65536)
47+
.with_heap_threshold(262144);
48+
let mut roots = Vec::new();
49+
for i in 0..num_objects {
50+
let root = Gc::new_in(GcRefCell::new(i), &collector);
51+
roots.push(root);
52+
}
53+
(collector, roots)
54+
},
55+
|(collector, roots)| {
56+
collector.collect();
57+
black_box(roots.len())
58+
},
59+
criterion::BatchSize::SmallInput,
60+
);
61+
},
62+
);
63+
}
64+
65+
group.finish();
66+
}
67+
68+
criterion_group!(benches, bench_alloc, bench_collect);
69+
criterion_main!(benches);

0 commit comments

Comments
 (0)