diff options
Diffstat (limited to 'zkvms_host_io')
| -rw-r--r-- | zkvms_host_io/input_macros/src/lib.rs | 25 | ||||
| -rw-r--r-- | zkvms_host_io/src/lib.rs | 22 |
2 files changed, 34 insertions, 13 deletions
diff --git a/zkvms_host_io/input_macros/src/lib.rs b/zkvms_host_io/input_macros/src/lib.rs index 7984d96..229d4e4 100644 --- a/zkvms_host_io/input_macros/src/lib.rs +++ b/zkvms_host_io/input_macros/src/lib.rs @@ -66,8 +66,14 @@ static DERIVES: &str = "#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deseria pub fn generate_output_type_input_struct(_: TokenStream) -> TokenStream { let fd = new_fd(); - let sep = if fd.public_types().is_empty() { "" } else { ", " }; - let output_type = format!("pub type Output = ({} {} {});", fd.grouped_public_types(), sep, fd.return_type).to_string(); + let sep = if fd.types().is_empty() { "" } else { ", " }; + let output_type = format!( + "pub type Output = ({} {} {});", + fd.grouped_public_types(), + sep, + fd.return_type + ) + .to_string(); let return_type = format!("pub type Return = {};", fd.return_type).to_string(); @@ -102,7 +108,8 @@ pub fn generate_output_type_input_struct(_: TokenStream) -> TokenStream { .map(|x| format!("input.{x},")) .collect::<String>(); let types = fd.grouped_types(); - let struct_def = &format!(" + let struct_def = &format!( + " {DERIVES} pub struct Input {{ {attrs} }} @@ -111,7 +118,9 @@ pub fn generate_output_type_input_struct(_: TokenStream) -> TokenStream { ({convertion}) }} }} - ").to_string(); + " + ) + .to_string(); (output_type + &return_type + &public_input_type + &private_input_type + &struct_def) .parse::<TokenStream>() @@ -159,7 +168,8 @@ pub fn foreach_private_input_field(item: TokenStream) -> TokenStream { /// parameters. #[proc_macro] pub fn benchmarkable(item: TokenStream) -> TokenStream { - format!(r#" + format!( + r#" {{ use std::time::Instant; @@ -182,5 +192,8 @@ pub fn benchmarkable(item: TokenStream) -> TokenStream { zkvms_host_io::emit_benchmark_results(run_info, starts, ends); }} }} - "#).parse().unwrap() + "# + ) + .parse() + .unwrap() } diff --git a/zkvms_host_io/src/lib.rs b/zkvms_host_io/src/lib.rs index a3249a0..584a883 100644 --- a/zkvms_host_io/src/lib.rs +++ b/zkvms_host_io/src/lib.rs @@ -159,14 +159,15 @@ pub fn output_proof_size<T>(proof: &T) { } pub fn output_proof_size_raw(size: usize) { - std::fs::write(PROOF_SIZE_FILE_PATH, size.to_string()).expect(&format!("Couldn't write proof size to \"{PROOF_SIZE_FILE_PATH}\"!")); + std::fs::write(PROOF_SIZE_FILE_PATH, size.to_string()).expect(&format!( + "Couldn't write proof size to \"{PROOF_SIZE_FILE_PATH}\"!" + )); } fn mean(xs: &Vec<f32>) -> f32 { if xs.len() == 1 { xs[0] - } - else { + } else { statistical::mean(&xs) } } @@ -174,8 +175,7 @@ fn mean(xs: &Vec<f32>) -> f32 { fn stddev(xs: &Vec<f32>) -> f32 { if xs.len() == 1 { 0.0 - } - else { + } else { statistical::standard_deviation(&xs, None) } } @@ -199,8 +199,16 @@ pub fn emit_benchmark_results(run_info: RunWith, starts: Vec<Instant>, ends: Vec run["mean"] = mean(&durations).into(); run["deviation"] = stddev(&durations).into(); - run["min"] = (*durations.iter().min_by(|a,b| a.partial_cmp(b).unwrap()).unwrap()).into(); - run["max"] = (*durations.iter().max_by(|a,b| a.partial_cmp(b).unwrap()).unwrap()).into(); + run["min"] = (*durations + .iter() + .min_by(|a, b| a.partial_cmp(b).unwrap()) + .unwrap()) + .into(); + run["max"] = (*durations + .iter() + .max_by(|a, b| a.partial_cmp(b).unwrap()) + .unwrap()) + .into(); run["memory"] = Null; run["proofSize"] = Null; |
