Skip to content

Commit

Permalink
more accurate bench
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Jun 8, 2023
1 parent 90e5d1d commit ffd24e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bench/criterion_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn parse_program(c: &mut Criterion) {
//Picked the biggest one at the time of writing
let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
c.bench_function("parse program", |b| {
b.iter(|| {
b.iter_with_large_drop(|| {
_ = Program::from_bytes(black_box(program.as_slice()), black_box(Some("main")))
.unwrap();
})
Expand All @@ -29,7 +29,7 @@ fn build_many_runners(c: &mut Criterion) {
let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
let program = Program::from_bytes(program.as_slice(), Some("main")).unwrap();
c.bench_function("build runner", |b| {
b.iter(|| {
b.iter_with_large_drop(|| {
_ = black_box(
CairoRunner::new(
black_box(&program),
Expand Down
9 changes: 5 additions & 4 deletions bench/iai_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use iai_callgrind::{black_box, main};
use core::hint::black_box;
use iai_callgrind::main;

use cairo_vm::{
types::program::Program,
Expand All @@ -18,7 +19,7 @@ fn parse_program() {
let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
let program =
Program::from_bytes(black_box(program.as_slice()), black_box(Some("main"))).unwrap();
let _ = black_box(program);
core::mem::drop(black_box(program));
}

#[export_name = "helper::parse_program"]
Expand All @@ -33,7 +34,7 @@ fn parse_program_helper() -> Program {
fn build_runner() {
let program = parse_program_helper();
let runner = CairoRunner::new(black_box(&program), "starknet_with_keccak", false).unwrap();
let _ = black_box(runner);
core::mem::drop(black_box(runner));
}

#[export_name = "helper::build_runner"]
Expand All @@ -54,6 +55,6 @@ fn load_program_data() {
}

main!(
callgrind_args = "toggle-collect=helper::*";
callgrind_args = "toggle-collect=helper::*,core::mem::drop";
functions = parse_program, build_runner, load_program_data
);

0 comments on commit ffd24e9

Please sign in to comment.