-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use cannon_mipsevm::{ | ||
load_elf, patch_go, patch_stack, | ||
test_utils::{ClaimTestOracle, StaticOracle}, | ||
InstrumentedState, PreimageOracle, | ||
}; | ||
use criterion::{criterion_group, criterion_main, Bencher, Criterion}; | ||
use std::io::BufWriter; | ||
|
||
fn bench_exec( | ||
elf_bytes: &[u8], | ||
oracle: impl PreimageOracle, | ||
compute_witness: bool, | ||
b: &mut Bencher, | ||
) { | ||
let mut state = load_elf(elf_bytes).unwrap(); | ||
patch_go(elf_bytes, &state).unwrap(); | ||
patch_stack(&mut state).unwrap(); | ||
|
||
let out = BufWriter::new(Vec::default()); | ||
let err = BufWriter::new(Vec::default()); | ||
let mut ins = InstrumentedState::new(state, oracle, out, err); | ||
|
||
b.iter(|| loop { | ||
if ins.state.exited { | ||
break; | ||
} | ||
ins.step(compute_witness).unwrap(); | ||
}) | ||
} | ||
|
||
fn execution(c: &mut Criterion) { | ||
c.bench_function("[No Witness] Execution (hello.elf)", |b| { | ||
let elf_bytes = include_bytes!("../../../example/bin/hello.elf"); | ||
bench_exec(elf_bytes, StaticOracle::default(), false, b); | ||
}); | ||
|
||
c.bench_function("[Witness] Execution (hello.elf)", |b| { | ||
let elf_bytes = include_bytes!("../../../example/bin/hello.elf"); | ||
bench_exec(elf_bytes, StaticOracle::default(), true, b); | ||
}); | ||
|
||
c.bench_function("[No Witness] Execution (claim.elf)", |b| { | ||
let elf_bytes = include_bytes!("../../../example/bin/claim.elf"); | ||
bench_exec(elf_bytes, ClaimTestOracle::default(), false, b); | ||
}); | ||
|
||
c.bench_function("[Witness] Execution (claim.elf)", |b| { | ||
let elf_bytes = include_bytes!("../../../example/bin/claim.elf"); | ||
bench_exec(elf_bytes, ClaimTestOracle::default(), true, b); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, execution); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters