aboutsummaryrefslogtreecommitdiff
path: root/zkvms_host_io/input_macros
diff options
context:
space:
mode:
Diffstat (limited to 'zkvms_host_io/input_macros')
-rw-r--r--zkvms_host_io/input_macros/src/lib.rs60
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()