forked from lambdaclass/cairo-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcriterion_benchmark.rs
62 lines (56 loc) · 2.12 KB
/
criterion_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
59
60
61
62
use cairo_vm::{
types::program::Program,
vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine},
};
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use mimalloc::MiMalloc;
#[global_allocator]
static ALLOC: MiMalloc = MiMalloc;
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_with_large_drop(|| {
_ = Program::from_bytes(black_box(program.as_slice()), black_box(Some("main")))
.unwrap();
})
});
}
fn build_many_runners(c: &mut Criterion) {
//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();
c.bench_function("build runner", |b| {
b.iter_with_large_drop(|| {
_ = black_box(
CairoRunner::new(
black_box(&program),
black_box("starknet_with_keccak"),
black_box(false),
)
.unwrap(),
);
})
});
}
fn load_program_data(c: &mut Criterion) {
//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();
c.bench_function("initialize", |b| {
b.iter_batched(
|| {
(
CairoRunner::new(&program, "starknet_with_keccak", false).unwrap(),
VirtualMachine::new(false),
)
},
|(mut runner, mut vm)| {
_ = black_box(runner.initialize(black_box(&mut vm), false).unwrap())
},
BatchSize::SmallInput,
)
});
}
criterion_group!(runner, build_many_runners, load_program_data, parse_program);
criterion_main!(runner);