-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
6399fec
commit ef99615
Showing
7 changed files
with
422 additions
and
464 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,47 @@ | ||
pub mod benches; | ||
pub mod nop; | ||
pub mod omni; | ||
pub mod poseidon2; | ||
pub mod sort; | ||
pub mod xor; | ||
|
||
use std::time::Duration; | ||
|
||
use anyhow::Result; | ||
pub use mozak_cli_args::bench_args::{BenchArgs, BenchFunction}; | ||
use nop::NopBench; | ||
use omni::OmniBench; | ||
use poseidon2::Poseidon2Bench; | ||
use sort::{SortBench, SortBenchRecursive}; | ||
use xor::XorBench; | ||
|
||
pub(crate) trait Bench { | ||
type Args; | ||
type Prepared; | ||
|
||
/// method to be executed to prepare the benchmark | ||
fn prepare(&self, args: &Self::Args) -> Self::Prepared; | ||
|
||
/// actual benchmark function, whose execution time is | ||
/// to be measured | ||
fn execute(&self, prepared: Self::Prepared) -> Result<()>; | ||
|
||
/// benchmark the `execute` function implemented through the | ||
/// trait `Bench` | ||
fn bench(&self, args: &Self::Args) -> Result<Duration> { | ||
let prepared = self.prepare(args); | ||
let start = std::time::Instant::now(); | ||
self.execute(prepared)?; | ||
Ok(start.elapsed()) | ||
} | ||
} | ||
|
||
pub fn bench(args: &BenchArgs) -> Result<Duration> { | ||
match &args.function { | ||
BenchFunction::XorBench { iterations } => XorBench.bench(iterations), | ||
BenchFunction::NopBench { iterations } => NopBench.bench(iterations), | ||
BenchFunction::OmniBench { iterations } => OmniBench.bench(iterations), | ||
BenchFunction::Poseidon2Bench { input_len } => Poseidon2Bench.bench(input_len), | ||
BenchFunction::SortBench { n } => SortBench.bench(n), | ||
BenchFunction::SortBenchRecursive { n } => SortBenchRecursive.bench(n), | ||
} | ||
} |
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
Oops, something went wrong.