Last active
February 12, 2021 18:03
-
-
Save yihuang/a96b6051833cc5e7d36b1cd4226b82c9 to your computer and use it in GitHub Desktop.
smol/tokio simple benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::time::Duration; | |
use criterion::{criterion_group, criterion_main, Criterion}; | |
use futures_lite::StreamExt; | |
async fn smol_timers(n: u64) { | |
let mut timer = smol::Timer::interval(Duration::new(0, 0)); | |
for _ in 0..n { | |
let _ = timer.next().await; | |
} | |
} | |
async fn tokio_timers(n: u64) { | |
let mut timer = tokio::time::interval(Duration::new(0, 0)); | |
for _ in 0..n { | |
let _ = timer.tick().await; | |
} | |
} | |
pub fn criterion_benchmark(c: &mut Criterion) { | |
let iterations = 1000; | |
let tokio_rt = tokio::runtime::Builder::new_current_thread().enable_time().build().unwrap(); | |
c.bench_function("smol timers", |b| b.iter(|| smol::block_on(smol_timers(iterations)))); | |
c.bench_function("tokio timers", |b| b.iter(|| tokio_rt.block_on(tokio_timers(iterations)))); | |
} | |
criterion_group!(benches, criterion_benchmark); | |
criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "async-benchmark" | |
version = "0.1.0" | |
authors = ["yihuang <[email protected]>"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
[dev-dependencies] | |
criterion = { version = "0.3", features = ["html_reports"] } | |
futures-lite = "1.11" | |
smol = "1.2" | |
# patched to support zero interval | |
tokio = { git = "https://github.com/yihuang/tokio.git", branch = "zero-interval", features = ["full"] } | |
[[bench]] | |
name = "async_benchmark" | |
harness = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo bench | |
Finished bench [optimized] target(s) in 0.08s | |
Running target/release/deps/async_benchmark-7c13411ed47f9d2f | |
smol timers time: [139.64 us 140.78 us 141.91 us] | |
change: [-1.1280% +0.5187% +2.2069%] (p = 0.53 > 0.05) | |
No change in performance detected. | |
Found 6 outliers among 100 measurements (6.00%) | |
3 (3.00%) high mild | |
3 (3.00%) high severe | |
Benchmarking tokio timers: Warming up for 3.0000 s | |
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 8.1s, enable flat sampling, or reduce sample count to 50. | |
tokio timers time: [1.6268 ms 1.6363 ms 1.6455 ms] | |
change: [-0.9383% -0.0372% +0.8718%] (p = 0.93 > 0.05) | |
No change in performance detected. | |
Found 5 outliers among 100 measurements (5.00%) | |
1 (1.00%) low severe | |
4 (4.00%) low mild |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment