diff --git a/src/lair/execute.rs b/src/lair/execute.rs index ca03f44b..ea88ba61 100644 --- a/src/lair/execute.rs +++ b/src/lair/execute.rs @@ -316,6 +316,23 @@ impl QueryRecord { pub fn expect_public_values(&self) -> &[F] { self.public_values.as_ref().expect("Public values not set") } + + pub fn stats>(&self, toplevel: &Toplevel) -> (usize, usize) { + let mut steps = 0; + let mut width = 0; + for (i, queries) in self.func_queries.iter().enumerate() { + steps += queries.len(); + let func = toplevel.get_by_index(i); + let func_width = func.compute_layout_sizes(toplevel).total(); + width += queries.len() * func_width; + } + for (i, queries) in self.mem_queries.iter().enumerate() { + steps += queries.len(); + let mem_width = 4 + mem_index_to_len(i); + width += queries.len() * mem_width; + } + (steps, width) + } } impl> Toplevel { diff --git a/src/lair/func_chip.rs b/src/lair/func_chip.rs index afa6b260..08b363e2 100644 --- a/src/lair/func_chip.rs +++ b/src/lair/func_chip.rs @@ -18,7 +18,7 @@ pub type LayoutSizes = ColumnLayout; impl LayoutSizes { #[inline] - fn total(&self) -> usize { + pub fn total(&self) -> usize { self.nonce + self.input + self.aux + self.sel } } diff --git a/src/lurk/cli/repl.rs b/src/lurk/cli/repl.rs index 042acfeb..6ba9ce76 100644 --- a/src/lurk/cli/repl.rs +++ b/src/lurk/cli/repl.rs @@ -42,7 +42,6 @@ pub(crate) struct Repl> { pub(crate) queries: QueryRecord, pub(crate) toplevel: Toplevel, pub(crate) lurk_main_idx: usize, - eval_idx: usize, pub(crate) env: ZPtr, state: StateRcCell, pwd_path: Utf8PathBuf, @@ -54,14 +53,12 @@ impl Repl { let (toplevel, mut zstore) = build_lurk_toplevel(); let queries = QueryRecord::new(&toplevel); let lurk_main_idx = toplevel.get_by_name("lurk_main").index; - let eval_idx = toplevel.get_by_name("eval").index; let env = zstore.intern_empty_env(); Self { zstore, queries, toplevel, lurk_main_idx, - eval_idx, env, state: State::init_lurk_state().rccell(), pwd_path: current_dir().expect("Couldn't get current directory"), @@ -70,11 +67,15 @@ impl Repl { } } -fn pretty_iterations_display(iterations: usize) -> String { +fn pretty_iterations_display(iterations: usize, width: usize) -> String { if iterations != 1 { - format!("{iterations} iterations") + let average_width = width as f64 / iterations as f64; + format!( + "{iterations} iterations, average step size {:.2}", + average_width + ) } else { - "1 iteration".into() + format!("1 iteration, width {width}") } } @@ -163,10 +164,10 @@ impl> Repl { self.queries.get_inv_queries("hash_32_8", &self.toplevel), self.queries.get_inv_queries("hash_48_8", &self.toplevel), ); - let iterations = self.queries.func_queries[self.eval_idx].len(); + let (iterations, width) = self.queries.stats(&self.toplevel); println!( "[{}] => {}", - pretty_iterations_display(iterations), + pretty_iterations_display(iterations, width), self.fmt(&output) ); }