Skip to content

Commit

Permalink
initial bench config
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Mar 10, 2018
1 parent 6e8817d commit bc950a8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xray_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ futures = "0.1"
[dev-dependencies]
futures-cpupool = "0.1"
tokio-core = "0.1"

[features]
dev = []
29 changes: 29 additions & 0 deletions xray_core/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "dev")]
extern crate test;

use std::cmp;
use std::collections::HashSet;
use std::iter;
Expand Down Expand Up @@ -500,6 +503,9 @@ fn find_insertion_index<T: Ord>(v: &Vec<T>, x: &T) -> usize {
mod tests {
use super::*;

#[cfg(feature = "dev")]
use super::test::Bencher;

impl Buffer {
fn to_string(&self) -> String {
String::from_utf16_lossy(self.iter().collect::<Vec<u16>>().as_slice())
Expand Down Expand Up @@ -610,4 +616,27 @@ mod tests {
}
}
}

#[bench]
fn bench_test(b: &mut Bencher) {
let mut buffer = Buffer::new(1);
b.iter(|| {
for seed in 0..100 {
use rand::{Rng, SeedableRng, StdRng};
let mut rng = StdRng::from_seed(&[seed]);

let mut ids = vec![FragmentId(vec![0]), FragmentId(vec![4])];
for _i in 0..100 {
let index = rng.gen_range::<usize>(1, ids.len());

let left = ids[index - 1].clone();
let right = ids[index].clone();
ids.insert(index, FragmentId::between_with_max(&left, &right, 4));

let mut sorted_ids = ids.clone();
sorted_ids.sort()
}
}
});
}
}
2 changes: 2 additions & 0 deletions xray_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(feature = "dev", feature(test))]

extern crate rand;
extern crate futures;

Expand Down

0 comments on commit bc950a8

Please sign in to comment.