Skip to content

Commit

Permalink
Fix existing benchmarks
Browse files Browse the repository at this point in the history
The #[cfg(bench)] attribute does not exist and is always false. Lets
define a feature "bench" which can be used to enable benchmarks when
building with nightly.
  • Loading branch information
michalsrb committed Nov 23, 2019
1 parent d9929a6 commit db8784f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ alloc = []
std = []
clock = ["time", "std"]
wasmbind = ["wasm-bindgen", "js-sys"]
bench = ["std"]

[dependencies]
time = { version = "0.1.39", optional = true }
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@

#![doc(html_root_url = "https://docs.rs/chrono/latest/")]

#![cfg_attr(bench, feature(test))] // lib stability features as per RFC #507
#![cfg_attr(feature = "bench", feature(test))] // lib stability features as per RFC #507
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]

Expand Down Expand Up @@ -427,6 +427,8 @@ extern crate doc_comment;
extern crate wasm_bindgen;
#[cfg(all(target_arch = "wasm32", feature="wasmbind"))]
extern crate js_sys;
#[cfg(feature = "bench")]
extern crate test;

#[cfg(test)]
doctest!("../README.md");
Expand Down
3 changes: 1 addition & 2 deletions src/naive/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ impl fmt::Debug for Mdf {
#[cfg(test)]
mod tests {
#[cfg(test)] extern crate num_iter;
#[cfg(bench)] extern crate test;

use Weekday;
use super::{Of, Mdf};
Expand Down Expand Up @@ -517,7 +516,7 @@ mod tests {
assert_eq!(GF.nisoweeks(), 52);
}

#[cfg(bench)]
#[cfg(feature = "bench")]
#[bench]
fn bench_year_flags_from_year(bh: &mut test::Bencher) {
bh.iter(|| {
Expand Down

0 comments on commit db8784f

Please sign in to comment.