-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
43 lines (35 loc) · 1.17 KB
/
main.rs
File metadata and controls
43 lines (35 loc) · 1.17 KB
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
use std::path::PathBuf;
use clap::{command, Parser};
use criterion::PlottingBackend;
mod benchmark;
#[derive(Parser, Debug)]
#[command(version, about)]
struct Args {
/// Path to the onnx model file.
model_path: PathBuf,
/// The number of samples to collect for each benchmark.
#[arg(short, long, default_value = "5000")]
samples: usize,
}
fn main() -> miette::Result<()> {
miette::set_panic_hook();
let args = Args::parse();
let model_path = args.model_path;
if !model_path.exists() {
eprintln!("Model file not found: {}", model_path.display());
std::process::exit(1);
}
let Some(model_path_str) = model_path.to_str() else {
eprintln!(
"Model file path is not valid UTF-8: {}",
model_path.display()
);
std::process::exit(1);
};
let mut criterion: ::criterion::Criterion<_> = ::criterion::Criterion::default()
.sample_size(args.samples)
// this is set to `None` to avoid having to pass the `--bench` argument
.profile_time(None)
.plotting_backend(PlottingBackend::Plotters);
benchmark::run_benchmark_onnx(model_path_str, &mut criterion)
}