浏览代码

chore: no benchmark-only dev-deps in tests (#11)

* chore: no benchmark-only dev-deps in tests
* chore(bench): put benchmarks in separate crate
* chore: add shell script for running loom config
* chore(build): fix tokio dev dep
* chore(test): make loom script nicer

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Eliza Weisman 3 年之前
父节点
当前提交
5e26864245
共有 7 个文件被更改,包括 54 次插入20 次删除
  1. 11 15
      Cargo.toml
  2. 27 0
      bench/Cargo.toml
  3. 2 2
      bench/benches/async_mpsc.rs
  4. 2 2
      bench/benches/sync_mpsc.rs
  5. 1 0
      bench/src/lib.rs
  6. 10 0
      bin/loom
  7. 1 1
      src/util/wait/wait_cell.rs

+ 11 - 15
Cargo.toml

@@ -1,3 +1,9 @@
+[workspace]
+members = [
+    ".",
+    "bench"
+]
+
 [package]
 name = "thingbuf"
 version = "0.1.0"
@@ -13,16 +19,14 @@ default = ["std"]
 [dependencies]
 
 [dev-dependencies]
+tokio = { version = "1.14.0", features = ["rt", "rt-multi-thread", "macros", "sync"] }
+# So that we can use `poll_fn` in tests.
+futures-util = { version = "0.3", default-features = false }
+
+[target.'cfg(loom)'.dev-dependencies]
 loom = { version = "0.5.3", features = ["checkpoint", "futures"] }
 tracing-subscriber = { version = "0.3", default-features = false, features = ["std", "fmt"] }
 tracing = { version = "0.1", default-features = false, features = ["std"] }
-# So that we can use `poll_fn` in tests.
-futures = "0.3"
-criterion = { version = "0.3.5", features = ["async_tokio"] }
-# for comparison benchmarks
-crossbeam = "0.8.1"
-tokio = { version = "1.14.0", features = ["rt", "rt-multi-thread", "sync", "macros"] }
-async-std = "1"
 
 # Custom profile for Loom tests: enable release optimizations so that the loom
 # tests are less slow, but don't disable debug assertions.
@@ -31,13 +35,5 @@ inherits = "test"
 lto = true
 opt-level = 3
 
-[[bench]]
-name = "sync_mpsc"
-harness = false
-
-[[bench]]
-name = "async_mpsc"
-harness = false
-
 [patch.crates-io]
 loom = { git = "https://github.com/tokio-rs/loom", branch = "eliza/fix-double-panic-in-drop" }

+ 27 - 0
bench/Cargo.toml

@@ -0,0 +1,27 @@
+[package]
+name = "bench"
+version = "0.1.0"
+edition = "2021"
+publish = false
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+
+[dev-dependencies]
+thingbuf = { path = ".." }
+criterion = { version = "0.3.5", features = ["async_tokio"] }
+
+# for comparison benchmarks
+tokio = { version = "1.14.0", features = ["rt", "rt-multi-thread", "sync"] }
+crossbeam = "0.8.1"
+async-std = "1"
+futures = "0.3"
+
+[[bench]]
+name = "sync_mpsc"
+harness = false
+
+[[bench]]
+name = "async_mpsc"
+harness = false

+ 2 - 2
benches/async_mpsc.rs → bench/benches/async_mpsc.rs

@@ -13,8 +13,8 @@ use tokio::{runtime, task};
 fn bench_spsc_reusable(c: &mut Criterion) {
     let mut group = c.benchmark_group("async/spsc_reusable");
     static THE_STRING: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
-    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
-    aaaaaaaaaaaaaa";
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
+aaaaaaaaaaaaaa";
 
     for size in [100, 500, 1_000, 5_000, 10_000] {
         group.throughput(Throughput::Elements(size));

+ 2 - 2
benches/sync_mpsc.rs → bench/benches/sync_mpsc.rs

@@ -13,8 +13,8 @@ use std::thread;
 fn bench_spsc_reusable(c: &mut Criterion) {
     let mut group = c.benchmark_group("sync/spsc_reusable");
     static THE_STRING: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
-    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
-    aaaaaaaaaaaaaa";
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
+aaaaaaaaaaaaaa";
 
     for size in [100, 500, 1_000, 5_000, 10_000] {
         group.throughput(Throughput::Elements(size));

+ 1 - 0
bench/src/lib.rs

@@ -0,0 +1 @@
+

+ 10 - 0
bin/loom

@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+set -x
+
+RUSTFLAGS="--cfg loom ${RUSTFLAGS}" \
+LOOM_LOG="${LOOM_LOG:-info}" \
+LOOM_MAX_PREEMPTIONS="${LOOM_MAX_PREEMPTIONS:-2}" \
+cargo test \
+    --profile loom \
+    "$@"

+ 1 - 1
src/util/wait/wait_cell.rs

@@ -280,7 +280,7 @@ mod tests {
     const NUM_NOTIFY: usize = 2;
 
     async fn wait_on(chan: Arc<Chan>) {
-        futures::future::poll_fn(move |cx| {
+        futures_util::future::poll_fn(move |cx| {
             let res = test_dbg!(chan.task.wait_with(|| cx.waker().clone()));
 
             if NUM_NOTIFY == chan.num.load(Relaxed) {