forked from lambdaclass/cairo-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiai_benchmark.rs
58 lines (49 loc) · 1.9 KB
/
iai_benchmark.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use core::hint::black_box;
use iai_callgrind::main;
use cairo_vm::{
types::program::Program,
vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine},
};
use mimalloc::MiMalloc;
#[global_allocator]
static ALLOC: MiMalloc = MiMalloc;
#[inline(never)]
fn parse_program() {
//Picked the biggest one at the time of writing
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();
core::mem::drop(black_box(program));
}
#[export_name = "helper::parse_program"]
#[inline(never)]
fn parse_program_helper() -> Program {
//Picked the biggest one at the time of writing
let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
Program::from_bytes(program.as_slice(), Some("main")).unwrap()
}
#[inline(never)]
fn build_runner() {
let program = parse_program_helper();
let runner = CairoRunner::new(black_box(&program), "starknet_with_keccak", false).unwrap();
core::mem::drop(black_box(runner));
}
#[export_name = "helper::build_runner"]
#[inline(never)]
fn build_runner_helper() -> (CairoRunner, VirtualMachine) {
//Picked the biggest one at the time of writing
let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
let program = Program::from_bytes(program.as_slice(), Some("main")).unwrap();
let runner = CairoRunner::new(&program, "starknet_with_keccak", false).unwrap();
let vm = VirtualMachine::new(false);
(runner, vm)
}
#[inline(never)]
fn load_program_data() {
let (mut runner, mut vm) = build_runner_helper();
_ = black_box(runner.initialize(black_box(&mut vm), false).unwrap());
}
main!(
callgrind_args = "toggle-collect=helper::*,core::mem::drop";
functions = parse_program, build_runner, load_program_data
);