Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearrange benches #175

Merged
merged 3 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ repository = "https://github.com/pingcap/rust-prometheus"
homepage = "https://github.com/pingcap/rust-prometheus"
documentation = "https://docs.rs/prometheus"

include = [
"LICENSE",
"Cargo.toml",
"src/**/*.rs",
"proto/**/*.rs",
"benches/**/*.rs",
]

[badges]
travis-ci = { repository = "pingcap/rust-prometheus" }

Expand All @@ -29,10 +21,6 @@ push = ["hyper", "libc"]
process = ["libc", "procinfo"]
gen = ["protobuf-codegen-pure"]

[[bench]]
name = "benches"
path = "benches/benches.rs"

[dependencies]
protobuf = "2.0"
quick-error = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dev: format
cargo test --features="${ENABLE_FEATURES} dev" -- --nocapture

bench: format
RUSTFLAGS="--cfg bench" cargo bench --features="${ENABLE_FEATURES}" -- --nocapture
cargo bench --features=${ENABLE_FEATURES} -- --nocapture

format:
@cargo fmt --all -- --write-mode diff >/dev/null || cargo fmt --all
Expand Down
29 changes: 24 additions & 5 deletions benches/benches.rs → benches/atomic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 PingCAP, Inc.
// Copyright 2018 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,10 +12,29 @@
// limitations under the License.

#![feature(test)]
#![cfg_attr(feature = "nightly", feature(integer_atomics))]

extern crate prometheus;
extern crate spin;
extern crate test;

mod counter;
mod gauge;
mod histogram;
#[path = "../src/atomic64/mod.rs"]
mod atomic64;

use atomic64::*;
use test::Bencher;

#[bench]
fn bench_atomic_f64(b: &mut Bencher) {
let val = AtomicF64::new(0.0);
b.iter(|| {
val.inc_by(12.0);
});
}

#[bench]
fn bench_atomic_i64(b: &mut Bencher) {
let val = AtomicI64::new(0);
b.iter(|| {
val.inc_by(12);
});
}
8 changes: 7 additions & 1 deletion benches/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use prometheus::{Counter, CounterVec, IntCounter, Opts};
#![feature(test)]

extern crate prometheus;
extern crate test;

use std::collections::HashMap;

use prometheus::{Counter, CounterVec, IntCounter, Opts};
use test::Bencher;

#[bench]
Expand Down
5 changes: 5 additions & 0 deletions benches/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(test)]

extern crate prometheus;
extern crate test;

use prometheus::{Gauge, GaugeVec, IntGauge, Opts};
use test::Bencher;

Expand Down
5 changes: 5 additions & 0 deletions benches/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(test)]

extern crate prometheus;
extern crate test;

use prometheus::{Histogram, HistogramOpts, HistogramVec};
use test::Bencher;

Expand Down
22 changes: 0 additions & 22 deletions src/atomic64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,3 @@ mod test {
assert_eq!(au64.get(), 123);
}
}

#[cfg(all(test, bench))]
mod bench {
use super::*;
use test::Bencher;

#[bench]
fn bench_atomic_f64(b: &mut Bencher) {
let val = AtomicF64::new(0.0);
b.iter(|| {
val.inc_by(12.0);
});
}

#[bench]
fn bench_atomic_i64(b: &mut Bencher) {
let val = AtomicI64::new(0);
b.iter(|| {
val.inc_by(12);
});
}
}
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
The Rust client library for [Prometheus](https://prometheus.io/).
*/

#![cfg_attr(all(test, bench), feature(test))]
#![cfg_attr(feature = "dev", feature(plugin))]
#![cfg_attr(feature = "dev", plugin(clippy))]
#![cfg_attr(not(feature = "dev"), allow(unknown_lints))]
Expand All @@ -38,8 +37,6 @@ extern crate protobuf;
#[macro_use]
extern crate quick_error;
extern crate spin;
#[cfg(all(test, bench))]
extern crate test;

mod encoder;
mod errors;
Expand Down