From cc2e14ba71d86df5799a8975147ec742d5ed8bf4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 9 Jun 2019 01:19:58 +0200 Subject: [PATCH 1/2] Support useticks --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1526a7a..76e043a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,7 +100,7 @@ struct Runtime<'a> { code: &'a [u8], libraries: &'a Vec, ticks_left: u32, - memory: Option, + pub memory: Option, pre_state: &'a Bytes32, block_data: &'a ShardBlockBody, post_state: Bytes32, From 007890721bcbfb16e622a3794c5ae72ce7fe52d2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 9 Jun 2019 10:11:41 +0200 Subject: [PATCH 2/2] Add benchmarking using criterion --- Cargo.toml | 5 +++++ scripts/bazaar/Cargo.toml | 1 + src/main.rs | 34 +++++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 835a4b9..f019513 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/scripts/bazaar/Cargo.toml b/scripts/bazaar/Cargo.toml index ae73537..322b682 100644 --- a/scripts/bazaar/Cargo.toml +++ b/scripts/bazaar/Cargo.toml @@ -20,3 +20,4 @@ crate-type = ["cdylib"] [profile.release] lto = true debug = false +opt-level = 3 diff --git a/src/main.rs b/src/main.rs index 76e043a..25d868d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,7 +100,7 @@ struct Runtime<'a> { code: &'a [u8], libraries: &'a Vec, ticks_left: u32, - pub memory: Option, + memory: Option, pre_state: &'a Bytes32, block_data: &'a ShardBlockBody, post_state: Bytes32, @@ -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 = 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 = 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);