summaryrefslogtreecommitdiffstats
path: root/benches
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-12-24 20:53:20 -0800
committerGitHub <noreply@github.com>2019-12-24 20:53:20 -0800
commit50b91c024718c13a5d3608c63b62b2627dea5fd7 (patch)
tree8465bd561e290410e16cc10bb9dd652898cda492 /benches
parent67bf9c36f347031ca05872d102a7f9abc8b465f0 (diff)
chore: move benches to separate crate (#2028)
This allows the `benches` crate to depend on `tokio` with all feature flags. This is a similar strategy used for `examples`.
Diffstat (limited to 'benches')
-rw-r--r--benches/Cargo.toml14
-rw-r--r--benches/spawn.rs70
2 files changed, 84 insertions, 0 deletions
diff --git a/benches/Cargo.toml b/benches/Cargo.toml
new file mode 100644
index 00000000..eb26903b
--- /dev/null
+++ b/benches/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "benches"
+version = "0.0.0"
+publish = false
+edition = "2018"
+
+[dependencies]
+tokio = { version = "0.2.0", path = "../tokio", features = ["full"] }
+bencher = "0.1.5"
+
+[[bench]]
+name = "spawn"
+path = "spawn.rs"
+harness = false
diff --git a/benches/spawn.rs b/benches/spawn.rs
new file mode 100644
index 00000000..78e0b784
--- /dev/null
+++ b/benches/spawn.rs
@@ -0,0 +1,70 @@
+//! Benchmark spawning a task onto the basic and threaded Tokio executors.
+//! This essentially measure the time to enqueue a task in the local and remote
+//! case.
+
+use bencher::{black_box, Bencher};
+
+async fn work() -> usize {
+ let val = 1 + 1;
+ black_box(val)
+}
+
+fn basic_scheduler_local_spawn(bench: &mut Bencher) {
+ let mut runtime = tokio::runtime::Builder::new()
+ .basic_scheduler()
+ .build()
+ .unwrap();
+ runtime.block_on(async {
+ bench.iter(|| {
+ let h = tokio::spawn(work());
+ black_box(h);
+ })
+ });
+}
+
+fn threaded_scheduler_local_spawn(bench: &mut Bencher) {
+ let mut runtime = tokio::runtime::Builder::new()
+ .threaded_scheduler()
+ .build()
+ .unwrap();
+ runtime.block_on(async {
+ bench.iter(|| {
+ let h = tokio::spawn(work());
+ black_box(h);
+ })
+ });
+}
+
+fn basic_scheduler_remote_spawn(bench: &mut Bencher) {
+ let runtime = tokio::runtime::Builder::new()
+ .basic_scheduler()
+ .build()
+ .unwrap();
+ let handle = runtime.handle();
+ bench.iter(|| {
+ let h = handle.spawn(work());
+ black_box(h);
+ });
+}
+
+fn threaded_scheduler_remote_spawn(bench: &mut Bencher) {
+ let runtime = tokio::runtime::Builder::new()
+ .threaded_scheduler()
+ .build()
+ .unwrap();
+ let handle = runtime.handle();
+ bench.iter(|| {
+ let h = handle.spawn(work());
+ black_box(h);
+ });
+}
+
+bencher::benchmark_group!(
+ benches,
+ basic_scheduler_local_spawn,
+ threaded_scheduler_local_spawn,
+ basic_scheduler_remote_spawn,
+ threaded_scheduler_remote_spawn
+);
+
+bencher::benchmark_main!(benches);