diff options
author | Aria <me@aria.rip> | 2024-01-17 13:10:48 +0000 |
---|---|---|
committer | Aria <me@aria.rip> | 2024-01-17 13:14:43 +0000 |
commit | 3a58cabd192c5ed1d5a7e62f861b890e3c8cdb58 (patch) | |
tree | 1986b830a5bf7a539c3977bbce5fc8d479e44186 /src/crates/cli | |
parent | 1fedc0261e47efc4510887c868ebaf0f6c37e28b (diff) |
feat(cli): better output for cost model command
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(()) } |