Skip to content

Commit

Permalink
Move benchmarks to a separate crate
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 3, 2023
1 parent ecfad9e commit 1d80bf4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 benches/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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 }

Expand Down Expand Up @@ -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
26 changes: 26 additions & 0 deletions bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion benches/chrono.rs → bench/benches/chrono.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
2 changes: 0 additions & 2 deletions benches/serde.rs → bench/benches/serde.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "__internal_bench")]

use criterion::{black_box, criterion_group, criterion_main, Criterion};

use chrono::NaiveDateTime;
Expand Down
1 change: 1 addition & 0 deletions bench/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file only exists to make `benches` a valid crate.

0 comments on commit 1d80bf4

Please sign in to comment.