Skip to content

Commit

Permalink
Merge pull request #41 from aerospike/f-bencher
Browse files Browse the repository at this point in the history
Switch to bencher crate
  • Loading branch information
jhecking authored Oct 12, 2017
2 parents e52feab + e49c20c commit aa54159
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ env_logger = "^0.4"
hex = "^0.2"
rustfmt = "^0.8"
skeptic = "0.9"
bencher = "^0.1.4"

[build-dependencies]
skeptic = "0.9"

[[bench]]
name = "client_server"
harness = false

[workspace]
members = ["tools/benchmark"]
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ To enable backtraces set the `RUST_BACKTRACE` environment variable:
<a name="Benchmarks"></a>
## Benchmarks

The micro-benchmarks in the `benches` directory require nightly Rust builds to execute:
The micro-benchmarks in the `benches` directory use the
[`bencher`](https://crates.io/crates/bencher) crate and can be run on Rust
stable releases:

$ export AEROSPIKE_HOSTS=127.0.0.1:3000
$ cargo +nightly bench
$ cargo bench

There is a separate benchmark tool under the
[tools/benchmark](tools/benchmark) directory that is designed to
Expand Down
30 changes: 16 additions & 14 deletions benches/client_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,50 @@
// License for the specific language governing permissions and limitations under
// the License.

#![feature(test)]

#[macro_use]
extern crate aerospike;
#[macro_use]
extern crate lazy_static;
extern crate rand;
extern crate test;
#[macro_use]
extern crate bencher;

use aerospike::{Bins, ReadPolicy, WritePolicy};

use test::Bencher;
use bencher::Bencher;

#[path="../tests/common/mod.rs"]
mod common;

#[bench]
fn single_key_read(b: &mut Bencher) {
lazy_static! {
static ref TEST_SET: String = common::rand_str(10);
}

fn single_key_read(bench: &mut Bencher) {
let client = common::client();
let namespace = common::namespace();
let set_name = &common::rand_str(10);
let key = as_key!(namespace, set_name, common::rand_str(10));
let key = as_key!(namespace, &TEST_SET, common::rand_str(10));
let wbin = as_bin!("i", 1);
let bins = vec![&wbin];
let rpolicy = ReadPolicy::default();
let wpolicy = WritePolicy::default();
client.put(&wpolicy, &key, &bins).unwrap();

b.iter(|| client.get(&rpolicy, &key, Bins::All).unwrap());
bench.iter(|| client.get(&rpolicy, &key, Bins::All).unwrap());
}

#[bench]
fn single_key_read_header(b: &mut Bencher) {
fn single_key_read_header(bench: &mut Bencher) {
let client = common::client();
let namespace = common::namespace();
let set_name = &common::rand_str(10);
let key = as_key!(namespace, set_name, common::rand_str(10));
let key = as_key!(namespace, &TEST_SET, common::rand_str(10));
let wbin = as_bin!("i", 1);
let bins = vec![&wbin];
let rpolicy = ReadPolicy::default();
let wpolicy = WritePolicy::default();
client.put(&wpolicy, &key, &bins).unwrap();

b.iter(|| client.get(&rpolicy, &key, Bins::None).unwrap());
bench.iter(|| client.get(&rpolicy, &key, Bins::None).unwrap());
}

benchmark_group!(benches, single_key_read, single_key_read_header);
benchmark_main!(benches);

0 comments on commit aa54159

Please sign in to comment.