36 lines
724 B
Rust
36 lines
724 B
Rust
use std::time::Duration;
|
|
|
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
use dust_lang::run;
|
|
|
|
const SOURCE: &str = r#"
|
|
let mut i = 0
|
|
|
|
while i < 1_000 {
|
|
i += 1
|
|
|
|
spawn(fn () {
|
|
let mut j = 0
|
|
|
|
while j < 5_000_000 {
|
|
j += 1
|
|
}
|
|
})
|
|
}
|
|
"#;
|
|
|
|
fn threads(source: &str) {
|
|
run(source).unwrap();
|
|
}
|
|
|
|
fn criterion_benchmark(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("threads");
|
|
|
|
group.measurement_time(Duration::from_secs(15));
|
|
group.bench_function("threads", |b| b.iter(|| threads(black_box(SOURCE))));
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
criterion_main!(benches);
|