Skip to content

Commit

Permalink
Add benchmarking using criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jan 25, 2020
1 parent cc2e14b commit 0078907
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ env_logger = "0.7"
primitive-types = "0.6"
ssz = "0.1.2"
ssz-derive = "0.1.2"
criterion = "0.2"

[[bench]]
name = "scout_bench"
harness = false
1 change: 1 addition & 0 deletions scripts/bazaar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ crate-type = ["cdylib"]
[profile.release]
lto = true
debug = false
opt-level = 3
34 changes: 23 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct Runtime<'a> {
code: &'a [u8],
libraries: &'a Vec<Library>,
ticks_left: u32,
pub memory: Option<MemoryRef>,
memory: Option<MemoryRef>,
pre_state: &'a Bytes32,
block_data: &'a ShardBlockBody,
post_state: Bytes32,
Expand Down Expand Up @@ -928,16 +928,28 @@ fn process_yaml_test(filename: &str) -> Result<(), ScoutError> {
Ok(())
}

fn main() {
env_logger::init();
#[macro_use]
extern crate criterion;

let args: Vec<String> = env::args().collect();
let ret = process_yaml_test(if args.len() != 2 {
"test.yaml"
} else {
&args[1]
use criterion::black_box;
use criterion::Criterion;

fn criterion_benchmark(c: &mut Criterion) {
env_logger::init();
c.bench_function("test", |b| {
b.iter(|| {
let args: Vec<String> = env::args().collect();
let ret = process_yaml_test(if args.len() != 2 {
"test.yaml"
} else {
&args[1]
});
if ret.is_err() {
println!("Unexpected test failure: {:?}", ret.err().unwrap())
}
})
});
if ret.is_err() {
println!("Unexpected test failure: {:?}", ret.err().unwrap())
}
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

0 comments on commit 0078907

Please sign in to comment.