Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions rust/benches/normal/add_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,29 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/

use criterion::{Bencher, Criterion, criterion_group, criterion_main};
use lightvm::{LightVM, types::capability::Capability};
use std::time::Duration;
fn bench_vm_execution(c: &mut Criterion) {
let mut vm = LightVM::new(vec![Capability::Control, Capability::Observe]);
fn main() {
let capabilities = vec![
Capability::Control,
Capability::Debug,
Capability::Observe,
];
let mut vm = LightVM::new(capabilities.clone());
let raw = r#"[
["val", "x"],
["push", 5],
["push", 8],
["add", "i16"],
["set", "x"]
]"#;
vm.load(raw.into());
let mut group = c.benchmark_group("LightVM Execution");
group.bench_function("add_bench", |b: &mut Bencher| {
b.iter(|| vm.run(None));
});
group.finish();
let tools = vm.tools();
let benchmark = tools.bench("add_bench").expect("benchmark requires debug capability");
benchmark.run(
|| {
let mut vm = LightVM::new(capabilities.clone());
vm.load(raw.into());
vm
},
|vm| vm.run(None),
);
}
fn custom_config() -> Criterion {
Criterion::default()
.sample_size(300)
.measurement_time(Duration::from_secs(15))
.warm_up_time(Duration::from_secs(3))
}
criterion_group! {
name = benches;
config = custom_config();
targets = bench_vm_execution
}
criterion_main!(benches);
Loading