Skip to content

Commit f6fb0bb

Browse files
committed
Added benchmark
1 parent c8ff8c6 commit f6fb0bb

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ tokio = { version = "1", default-features = false, features = ["sync"] }
1919

2020
[dev-dependencies]
2121
tokio = { version = "1", features = ["full"] }
22+
criterion = "0.5"
23+
24+
[[bench]]
25+
name = "benchmark"
26+
harness = false

benches/benchmark.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
3+
use ticked_async_executor::TickedAsyncExecutor;
4+
5+
fn spawn_tasks_benchmark(c: &mut Criterion) {
6+
c.bench_function("1 task", |b| {
7+
b.iter_with_large_drop(|| {
8+
let mut executor = TickedAsyncExecutor::default();
9+
executor.spawn_local("empty", async move {}).detach();
10+
executor.tick(0.1, None);
11+
assert_eq!(executor.num_tasks(), 0);
12+
});
13+
});
14+
15+
c.bench_function("2 tasks", |b| {
16+
b.iter_with_large_drop(|| {
17+
let mut executor = TickedAsyncExecutor::default();
18+
executor.spawn_local("empty1", async move {}).detach();
19+
executor.spawn_local("empty2", async move {}).detach();
20+
21+
executor.tick(0.1, None);
22+
assert_eq!(executor.num_tasks(), 0);
23+
});
24+
});
25+
}
26+
27+
criterion_group!(benches, spawn_tasks_benchmark);
28+
criterion_main!(benches);

0 commit comments

Comments
 (0)