Skip to content

Commit edeb31b

Browse files
authored
Merge branch 'main' into Uint512DivModHint
2 parents b533ba3 + fd2e499 commit edeb31b

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

.github/workflows/iai_main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
pip install -r requirements.txt
2626
sudo apt update
2727
sudo apt install -y valgrind
28+
cargo install --version 0.3.1 iai-callgrind-runner
2829
# NB: this should never result in a hit, but rather just populate for PRs
2930
- name: Initialize IAI cache for ${{ github.sha }}
3031
uses: actions/cache@v3

.github/workflows/iai_pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
pip install -r requirements.txt
2828
sudo apt update
2929
sudo apt install -y valgrind
30+
cargo install --version 0.3.1 iai-callgrind-runner
3031
- name: Initialize IAI cache for ${{ github.event.pull_request.base.sha }}
3132
uses: actions/cache@v3
3233
id: cache-iai-results
@@ -61,6 +62,7 @@ jobs:
6162
pip install -r requirements.txt
6263
sudo apt update
6364
sudo apt install -y valgrind
65+
cargo install --version 0.3.1 iai-callgrind-runner
6466
- name: Initialize IAI cache for ${{ github.event.pull_request.base.sha }}
6567
uses: actions/cache@v3
6668
id: cache-iai-results

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ rstest = { version = "0.17.0", default-features = false }
9898
wasm-bindgen-test = "0.3.34"
9999

100100
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
101-
iai = "0.1"
101+
iai-callgrind = "0.3.1"
102102
rusty-hook = "0.11"
103103
criterion = { version = "0.3", features = ["html_reports"] }
104104
proptest = "1.0.0"

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ $(cairo-repo-dir):
115115
cd cairo; cargo b --release --bin starknet-compile --bin starknet-sierra-compile
116116

117117
cargo-deps:
118+
cargo install --version 0.3.1 iai-callgrind-runner
118119
cargo install --version 1.1.0 cargo-criterion
119120
cargo install --version 0.6.1 flamegraph
120121
cargo install --version 1.14.0 hyperfine

bench/iai_benchmark.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use iai::{black_box, main};
1+
use iai_callgrind::{black_box, main};
22

33
use cairo_vm::{
44
types::program::Program,
@@ -12,6 +12,7 @@ use mimalloc::MiMalloc;
1212
#[global_allocator]
1313
static ALLOC: MiMalloc = MiMalloc;
1414

15+
#[inline(never)]
1516
fn parse_program() {
1617
//Picked the biggest one at the time of writing
1718
let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
@@ -20,25 +21,39 @@ fn parse_program() {
2021
let _ = black_box(program);
2122
}
2223

23-
fn build_many_runners() {
24+
#[export_name = "helper::parse_program"]
25+
#[inline(never)]
26+
fn parse_program_helper() -> Program {
2427
//Picked the biggest one at the time of writing
2528
let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
26-
let program = Program::from_bytes(program.as_slice(), Some("main")).unwrap();
27-
for _ in 0..100 {
28-
let runner = CairoRunner::new(black_box(&program), "starknet_with_keccak", false).unwrap();
29-
let _ = black_box(runner);
30-
}
29+
Program::from_bytes(program.as_slice(), Some("main")).unwrap()
3130
}
3231

33-
fn load_program_data() {
32+
#[inline(never)]
33+
fn build_runner() {
34+
let program = parse_program_helper();
35+
let runner = CairoRunner::new(black_box(&program), "starknet_with_keccak", false).unwrap();
36+
let _ = black_box(runner);
37+
}
38+
39+
#[export_name = "helper::build_runner"]
40+
#[inline(never)]
41+
fn build_runner_helper() -> (CairoRunner, VirtualMachine) {
3442
//Picked the biggest one at the time of writing
3543
let program = include_bytes!("../cairo_programs/benchmarks/keccak_integration_benchmark.json");
3644
let program = Program::from_bytes(program.as_slice(), Some("main")).unwrap();
37-
for _ in 0..100 {
38-
let mut runner = CairoRunner::new(&program, "starknet_with_keccak", false).unwrap();
39-
let mut vm = VirtualMachine::new(false);
40-
_ = black_box(runner.initialize(black_box(&mut vm)).unwrap());
41-
}
45+
let runner = CairoRunner::new(&program, "starknet_with_keccak", false).unwrap();
46+
let vm = VirtualMachine::new(false);
47+
(runner, vm)
48+
}
49+
50+
#[inline(never)]
51+
fn load_program_data() {
52+
let (mut runner, mut vm) = build_runner_helper();
53+
_ = black_box(runner.initialize(black_box(&mut vm)).unwrap());
4254
}
4355

44-
main!(parse_program, build_many_runners, load_program_data);
56+
main!(
57+
callgrind_args = "toggle-collect=helper::*";
58+
functions = parse_program, build_runner, load_program_data
59+
);

0 commit comments

Comments
 (0)