diff options
| author | Kamen Mladenov <kamen@syndamia.com> | 2025-03-28 12:16:55 +0200 |
|---|---|---|
| committer | Kamen Mladenov <kamen@syndamia.com> | 2025-05-02 15:32:54 +0300 |
| commit | 9f3bb196309a467a835759babe60b38ba0520656 (patch) | |
| tree | b79f610c0710c0116817f9fccfe4ead22ee349d8 /zkvms_host_io/input_macros/src/lib.rs | |
| parent | db7747fc25a69404bb241a306a337977fce9ae0f (diff) | |
| download | zkVMs-benchmarks-9f3bb196309a467a835759babe60b38ba0520656.tar zkVMs-benchmarks-9f3bb196309a467a835759babe60b38ba0520656.tar.gz zkVMs-benchmarks-9f3bb196309a467a835759babe60b38ba0520656.zip | |
feat(zkvms_host_io): Move metrics output from the benchmarkable macro to zkvsm_host_io lib
Diffstat (limited to 'zkvms_host_io/input_macros/src/lib.rs')
| -rw-r--r-- | zkvms_host_io/input_macros/src/lib.rs | 60 |
1 files changed, 3 insertions, 57 deletions
diff --git a/zkvms_host_io/input_macros/src/lib.rs b/zkvms_host_io/input_macros/src/lib.rs index 448f76e..7984d96 100644 --- a/zkvms_host_io/input_macros/src/lib.rs +++ b/zkvms_host_io/input_macros/src/lib.rs @@ -161,11 +161,8 @@ pub fn foreach_private_input_field(item: TokenStream) -> TokenStream { pub fn benchmarkable(item: TokenStream) -> TokenStream { format!(r#" {{ - use std::time::{{Duration, Instant}}; - use std::fs::OpenOptions; - use std::io::Write; - use std::path::Path; - + use std::time::Instant; + let mut starts = Vec::new(); let mut ends = Vec::new(); @@ -182,58 +179,7 @@ pub fn benchmarkable(item: TokenStream) -> TokenStream { }} if run_info.benchmarking {{ - let info_row = format!("name,guest,total duration,repeats,average\n"); - let mut output = format!("{{}},{{}},", env!("ZKVM"), env!("GUEST")); - - let duration = *ends.last().unwrap() - *starts.first().unwrap(); - if run_info.millis {{ - output += &format!("{{}},", duration.as_millis()); - }} else {{ - output += &format!("{{:.3}},", duration.as_secs_f32()); - }} - - let durations = starts - .into_iter() - .zip(ends.into_iter()) - .map(|(s,e)| e - s ) - .collect::<Vec<Duration>>(); - let average = durations.iter().sum::<Duration>() / durations.len() as u32; - - if run_info.millis {{ - output += &format!("{{}},{{}}\n", run_info.repeats, average.as_millis()); - }} else {{ - output += &format!("{{}},{{:.3}}\n", run_info.repeats, average.as_secs_f32()); - }} - - if let Some(file) = run_info.output_file {{ - - let file_exists = Path::new(&file).exists(); - - let mut outfile = match OpenOptions::new() - .write(true) - .create(true) - .append(run_info.append) - .open(&file) - {{ - Ok(file) => file, - Err(e) => {{ - panic!("Failed to open file: {{}}", e); - }} - }}; - - if !file_exists {{ - if let Err(e) = write!(outfile, "{{}}", info_row) {{ - panic!("Failed to write info_row: {{}}", e); - }} - }} - - if let Err(e) = write!(outfile, "{{}}", output) {{ - panic!("Failed to write output: {{}}", e); - }} - }} - else {{ - print!("{{}}", output); - }} + zkvms_host_io::emit_benchmark_results(run_info, starts, ends); }} }} "#).parse().unwrap() |
