aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crates/candelabra/src/cost/fit.rs2
-rw-r--r--src/crates/candelabra/src/cost/mod.rs2
-rw-r--r--src/crates/cli/src/model.rs31
3 files changed, 32 insertions, 3 deletions
diff --git a/src/crates/candelabra/src/cost/fit.rs b/src/crates/candelabra/src/cost/fit.rs
index ace3634..b3ae9ba 100644
--- a/src/crates/candelabra/src/cost/fit.rs
+++ b/src/crates/candelabra/src/cost/fit.rs
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
/// Estimates durations using a 3rd-order polynomial.
#[derive(Debug, Clone, Deserialize, Serialize)]
-pub struct Estimator([f64; 4]);
+pub struct Estimator(pub [f64; 4]);
/// Approximate cost of an action.
/// This is an approximation for the number of nanoseconds it would take.
diff --git a/src/crates/candelabra/src/cost/mod.rs b/src/crates/candelabra/src/cost/mod.rs
index ce807b5..85adac6 100644
--- a/src/crates/candelabra/src/cost/mod.rs
+++ b/src/crates/candelabra/src/cost/mod.rs
@@ -24,7 +24,7 @@ use crate::{
/// Cost model for a container, capable of estimating cost of each supported operation.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CostModel {
- by_op: HashMap<String, Estimator>,
+ pub by_op: HashMap<String, Estimator>,
}
/// Information for getting & caching cost information for container implementations.
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(())
}