From bb44f0b06d5cd2efe38da44d1f1ddc36ca2a575c Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Thu, 10 Aug 2023 13:04:17 +0700 Subject: [PATCH 1/3] Update CI (#707) * plot/Cargo.toml: Remove outdated CI badges. crates.io doesn't support this and they're outdated anyway. * ci: Update actions. Use `actions/checkout@v3` to remove a warning about old versions of node. Use `dtolay/rust-toolchain` instead of `actions-rs/toolchain` as it is maintained (and `actions-rs` actions are not). This also resolves a number of warnings about deprecated functionality within the GitHub Actions UI. Update one usage of `Swatimem/rust-cache` to v2. The other already was updated. Use `cargo` directly instead of using `actions-rs/cargo` as that action is also unmaintained. * ci: Disable wasi test except on stable. This results in an error when building with 1.64 despite `AsFd` having been added in 1.63. It was fixed in 1.66: https://github.com/rust-lang/rust/issues/103306 --- .github/workflows/audit.yml | 2 +- .github/workflows/ci.yaml | 64 ++++++++++++------------------------- plot/Cargo.toml | 2 -- 3 files changed, 22 insertions(+), 46 deletions(-) diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 118008c6..8daeb296 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -8,7 +8,7 @@ jobs: security_audit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - uses: actions-rs/audit-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 44a5fffe..93b71c87 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,63 +24,43 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@master name: Setup rust toolchain with: - profile: minimal toolchain: ${{ matrix.rust }} - override: true components: rustfmt, clippy - uses: Swatinem/rust-cache@v2 name: Load dependencies from cache - - uses: actions-rs/cargo@v1 - name: Build with stable features - with: - command: build - args: --features stable + - name: Build with stable features + run: cargo build --features stable - - uses: actions-rs/cargo@v1 + - name: Build with unstable features if: ${{ matrix.rust == 'nightly' }} - name: Build with unstable features - with: - command: build - args: --all-features + run: cargo build --all-features - - uses: actions-rs/cargo@v1 - name: Build with minimal features - with: - command: build - args: --no-default-features + - name: Build with minimal features + run: cargo build --no-default-features - - uses: actions-rs/cargo@v1 - name: Test with stable features - with: - command: test - args: --features stable + - name: Test with stable features + run: cargo test --features stable - - uses: actions-rs/cargo@v1 - name: Test with minimal features - with: - command: test - args: --no-default-features + - name: Test with minimal features + run: cargo test --no-default-features - - uses: actions-rs/cargo@v1 - name: Check for non-standard formatting + - name: Check for non-standard formatting if: ${{ matrix.rust == 'stable' }} - with: - command: fmt - args: --all -- --check + run: cargo fmt --all -- --check - - uses: actions-rs/cargo@v1 - name: Check for clippy hints + - name: Check for clippy hints if: ${{ matrix.rust == 'stable' }} - with: - command: clippy - args: -- -D warnings + run: cargo clippy -- -D warnings + # This fails on 1.64, but works on 1.66 and later. + # https://github.com/rust-lang/rust/issues/103306 - name: Test run targeting WASI + if: ${{ matrix.rust == 'stable' }} run: | curl https://wasmtime.dev/install.sh -sSf | bash source ~/.bashrc @@ -97,16 +77,14 @@ jobs: - stable steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 + - uses: dtolnay/rust-toolchain@master with: - profile: minimal toolchain: ${{ matrix.rust }} - override: true components: rustfmt, clippy - - uses: Swatinem/rust-cache@v1 + - uses: Swatinem/rust-cache@v2 - uses: taiki-e/install-action@nextest diff --git a/plot/Cargo.toml b/plot/Cargo.toml index 94668a0d..93178b0b 100644 --- a/plot/Cargo.toml +++ b/plot/Cargo.toml @@ -21,6 +21,4 @@ num-complex = { version = "0.4", default-features = false, features = ["std"] } rand = "0.8" [badges] -travis-ci = { repository = "bheisler/criterion.rs" } -appveyor = { repository = "bheisler/criterion.rs", id = "4255ads9ctpupcl2" } maintenance = { status = "looking-for-maintainer" } From 1b7ca528beaff4e6f0e07368a1058726df32695f Mon Sep 17 00:00:00 2001 From: Indradb <60851042+Indra-db@users.noreply.github.com> Date: Thu, 10 Aug 2023 07:13:46 +0100 Subject: [PATCH 2/3] Update comparing_functions.md (#706) wrap the for loop index in a black_box to prevent optimizations to happen, which lead to incorrect benchmark comparison. On my machine without the blackbox the slow function took 200 picoseconds while the fast took 2.5ns. --- book/src/user_guide/comparing_functions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/book/src/user_guide/comparing_functions.md b/book/src/user_guide/comparing_functions.md index 5c27a07c..0bc05e83 100644 --- a/book/src/user_guide/comparing_functions.md +++ b/book/src/user_guide/comparing_functions.md @@ -5,7 +5,7 @@ graphs to show the differences in performance between them. First, lets create a benchmark. We can even combine this with benchmarking over a range of inputs. ```rust -use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId}; +use criterion::{black_box, criterion_group, criterion_main, Criterion, BenchmarkId}; fn fibonacci_slow(n: u64) -> u64 { match n { @@ -55,9 +55,9 @@ fn bench_fibs(c: &mut Criterion) { let mut group = c.benchmark_group("Fibonacci"); for i in [20u64, 21u64].iter() { group.bench_with_input(BenchmarkId::new("Recursive", i), i, - |b, i| b.iter(|| fibonacci_slow(*i))); + |b, i| b.iter(|| fibonacci_slow(black_box(*i)))); group.bench_with_input(BenchmarkId::new("Iterative", i), i, - |b, i| b.iter(|| fibonacci_fast(*i))); + |b, i| b.iter(|| fibonacci_fast(black_box(*i)))); } group.finish(); } From 928d8a96dfd755dc14eb0f4821c196a9ec73cc9f Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 10 Aug 2023 14:16:21 +0800 Subject: [PATCH 3/3] Enable `--help` messages and accept `--include-ignored` as no-op (#703) * Enable `--help` for CLI Since clap 4, it requires the `help` feature to work. * Accept `--include-ignored` for compatibility This is a popular libtest parameter in CI to run all tests including non-ignored and ignored ones. In our case, we have no "ignored" semantics, thus it should be a no-op. --- Cargo.toml | 2 +- src/lib.rs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b7312417..b3b745d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ serde_json = "1.0" serde_derive = "1.0" ciborium = "0.2.0" is-terminal = "0.4.6" -clap = { version = "4", default-features = false, features = ["std"] } +clap = { version = "4", default-features = false, features = ["std", "help"] } walkdir = "2.3" tinytemplate = "1.1" cast = "0.3" diff --git a/src/lib.rs b/src/lib.rs index 855c68ff..f349d648 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -906,6 +906,11 @@ impl Criterion { .num_args(0) .hide(true) .help("Ignored, but added for compatibility with libtest.")) + .arg(Arg::new("include-ignored") + .long("include-ignored") + .num_args(0) + .hide(true) + .help("Ignored, but added for compatibility with libtest.")) .arg(Arg::new("version") .hide(true) .short('V')