diff options
Diffstat (limited to 'src/crates/cli')
-rw-r--r-- | src/crates/cli/src/model.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/crates/cli/src/model.rs b/src/crates/cli/src/model.rs index 58f0639..42d9bf0 100644 --- a/src/crates/cli/src/model.rs +++ b/src/crates/cli/src/model.rs @@ -1,6 +1,7 @@ use anyhow::Result; use argh::FromArgs; use log::info; +use tabled::{builder::Builder, settings::Style}; use crate::State; @@ -18,7 +19,35 @@ impl State { info!("Calculating cost model for {}", &args.name); let model = self.inner.cost_model(&args.name)?; - dbg!(model); + // Table of parameters + let mut builder = Builder::default(); + builder.set_header(["op", "x^3", "x^2", "x", "+ c"]); + for (k, v) in model.by_op.iter() { + builder.push_record(&[ + k.to_string(), + format!("{0:.5}", v.0[3]), + format!("{0:.5}", v.0[2]), + format!("{0:.5}", v.0[1]), + format!("{0:.5}", v.0[0]), + ]); + } + + println!("{}", builder.build().with(Style::sharp())); + + // Table of example cost estimates + let mut builder = Builder::default(); + builder.set_header(["op", "n = 1", "n = 100", "n = 1_000", "n = 10_000"]); + for (k, v) in model.by_op.iter() { + builder.push_record(&[ + k.to_string(), + format!("{0:.3}", v.estimate(1)), + format!("{0:.3}", v.estimate(100)), + format!("{0:.3}", v.estimate(1_000)), + format!("{0:.3}", v.estimate(10_000)), + ]); + } + + println!("{}", builder.build().with(Style::sharp())); Ok(()) } |