From e39346e2877b3a5445953f2bc5b64263cf46fc72 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Fri, 1 Sep 2023 18:28:46 +0200 Subject: [PATCH] Move benchmarks to a separate crate --- .github/workflows/lint.yml | 4 ++++ .github/workflows/test.yml | 2 +- Cargo.toml | 13 +------------ bench/Cargo.toml | 26 ++++++++++++++++++++++++++ {benches => bench/benches}/chrono.rs | 1 - {benches => bench/benches}/serde.rs | 2 -- bench/src/lib.rs | 1 + 7 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 bench/Cargo.toml rename {benches => bench/benches}/chrono.rs (99%) rename {benches => bench/benches}/serde.rs (95%) create mode 100644 bench/src/lib.rs diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6209a0ea65..1bbceb150c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,12 +17,16 @@ jobs: - uses: Swatinem/rust-cache@v2 - run: cargo fmt --check -- --color=always - run: cargo fmt --check --manifest-path fuzz/Cargo.toml + - run: cargo fmt --check --manifest-path bench/Cargo.toml - run: | cargo clippy --all-features --all-targets --color=always \ -- -D warnings - run: | cargo clippy --manifest-path fuzz/Cargo.toml --color=always \ -- -D warnings + - run: | + cargo clippy --manifest-path bench/Cargo.toml --color=always \ + -- -D warnings env: RUSTFLAGS: "-Dwarnings" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 00be669f85..3c98174cb8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,7 +57,7 @@ jobs: with: toolchain: ${{ matrix.rust_version }} - uses: Swatinem/rust-cache@v2 - - run: cargo check --benches + - run: cargo check --manifest-path bench/Cargo.toml --benches - run: cargo check --manifest-path fuzz/Cargo.toml --all-targets # run --lib and --doc to avoid the long running integration tests # which are run elsewhere diff --git a/Cargo.toml b/Cargo.toml index 390b0e76ab..47a7159a95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ clock = ["std", "winapi", "iana-time-zone", "android-tzdata"] oldtime = ["time"] wasmbind = ["wasm-bindgen", "js-sys"] unstable-locales = ["pure-rust-locales", "alloc"] -__internal_bench = ["criterion"] +__internal_bench = [] __doctest = [] [dependencies] @@ -35,7 +35,6 @@ num-traits = { version = "0.2", default-features = false } rustc-serialize = { version = "0.3.20", optional = true } serde = { version = "1.0.99", default-features = false, optional = true } pure-rust-locales = { version = "0.6", optional = true } -criterion = { version = "0.4.0", optional = true } rkyv = { version = "0.7", optional = true } arbitrary = { version = "1.0.0", features = ["derive"], optional = true } @@ -71,13 +70,3 @@ rustdoc-args = ["--cfg", "docsrs"] [package.metadata.playground] features = ["serde"] - -[[bench]] -name = "chrono" -required-features = ["__internal_bench"] -harness = false - -[[bench]] -name = "serde" -required-features = ["__internal_bench", "serde"] -harness = false diff --git a/bench/Cargo.toml b/bench/Cargo.toml new file mode 100644 index 0000000000..4c14068877 --- /dev/null +++ b/bench/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "benches" +version = "0.1.0" +edition = "2021" + +# Even as a `dev-dependency` Criterion and its dependencies can affect the MSRV of chrono. +# But not when it lives in a separate crate :-). +# See https://github.com/chronotope/chrono/pull/1104. + +[lib] +name = "benches" + +[dependencies] +chrono = { path = "..", features = ["__internal_bench", "serde"] } + +[[bench]] +name = "chrono" +harness = false + +[[bench]] +name = "serde" +harness = false + +[dev-dependencies] +criterion = "0.5.0" +serde_json = "1" diff --git a/benches/chrono.rs b/bench/benches/chrono.rs similarity index 99% rename from benches/chrono.rs rename to bench/benches/chrono.rs index 3f74923af2..8cf7b15616 100644 --- a/benches/chrono.rs +++ b/bench/benches/chrono.rs @@ -1,5 +1,4 @@ //! Benchmarks for chrono that just depend on std -#![cfg(feature = "__internal_bench")] use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; diff --git a/benches/serde.rs b/bench/benches/serde.rs similarity index 95% rename from benches/serde.rs rename to bench/benches/serde.rs index e9de4408e9..ee4deb5a49 100644 --- a/benches/serde.rs +++ b/bench/benches/serde.rs @@ -1,5 +1,3 @@ -#![cfg(feature = "__internal_bench")] - use criterion::{black_box, criterion_group, criterion_main, Criterion}; use chrono::NaiveDateTime; diff --git a/bench/src/lib.rs b/bench/src/lib.rs new file mode 100644 index 0000000000..d87371caaa --- /dev/null +++ b/bench/src/lib.rs @@ -0,0 +1 @@ +// This file only exists to make `benches` a valid crate.