aboutsummaryrefslogtreecommitdiff
path: root/src/crates/cli
diff options
context:
space:
mode:
authorAria <me@aria.rip>2023-11-23 16:10:34 +0000
committerAria <me@aria.rip>2023-11-23 16:10:34 +0000
commitc12c346327234261a41ed1b2ff77c5f9dfbba2b0 (patch)
treec1bb11769c060b3eca180e9014bdfb84aa751b2e /src/crates/cli
parent47bf7c0a78052e61b4083f3e9f3f5f0fea82b40d (diff)
refactor(cli): store benchmark results alongside cost model
Diffstat (limited to 'src/crates/cli')
-rw-r--r--src/crates/cli/src/cost/fit.rs2
-rw-r--r--src/crates/cli/src/cost/mod.rs16
-rw-r--r--src/crates/cli/src/main.rs9
3 files changed, 15 insertions, 12 deletions
diff --git a/src/crates/cli/src/cost/fit.rs b/src/crates/cli/src/cost/fit.rs
index 746c2a5..6c37521 100644
--- a/src/crates/cli/src/cost/fit.rs
+++ b/src/crates/cli/src/cost/fit.rs
@@ -3,8 +3,10 @@
use candelabra_benchmarker::Observation;
use na::{Dyn, MatrixXx4, OVector};
+use serde::{Deserialize, Serialize};
/// Estimates durations using a 3rd-order polynomial.
+#[derive(Debug, Deserialize, Serialize)]
pub struct Estimator([f64; 4]);
/// Approximate cost of an action.
diff --git a/src/crates/cli/src/cost/mod.rs b/src/crates/cli/src/cost/mod.rs
index 7f8d473..b492dfa 100644
--- a/src/crates/cli/src/cost/mod.rs
+++ b/src/crates/cli/src/cost/mod.rs
@@ -11,16 +11,15 @@ use log::{debug, warn};
use primrose::{LibSpec, LibSpecs};
use serde::{Deserialize, Serialize};
+use self::fit::Estimator;
use crate::{
cache::{gen_tree_hash, FileCache},
cost::benchmark::run_benchmarks,
paths::Paths,
};
-use self::fit::Estimator;
-
/// Cost model for a container, capable of estimating cost of each supported operation.
-#[derive(Serialize, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
pub struct CostModel {
by_op: HashMap<String, Estimator>,
}
@@ -30,6 +29,7 @@ pub struct CostModel {
struct CacheEntry {
lib_hash: u64,
model: CostModel,
+ results: Results,
}
/// Entry in the benchmark cache, but borrowing the cost model so we don't need to clone it
@@ -37,6 +37,7 @@ struct CacheEntry {
struct CacheEntryBorrowed<'a> {
lib_hash: u64,
model: &'a CostModel,
+ results: &'a Results,
}
/// Gets/retrieves benchmark results for container implementations.
@@ -84,8 +85,8 @@ impl<'a> ResultsStore<'a> {
} else {
debug!("Cache miss for {} benchmarks", name);
let results = run_benchmarks(name, self.paths, &self.lib_specs)?;
- let model = build_cost_model(results)?;
- if let Err(e) = self.put(name, &model) {
+ let model = build_cost_model(results.clone())?;
+ if let Err(e) = self.put(name, &model, &results) {
warn!("Error caching benchmark outputs for {}: {}", name, e);
}
Ok(model)
@@ -102,12 +103,13 @@ impl<'a> ResultsStore<'a> {
}
/// Store a new set of results with the given key
- fn put(&self, name: &str, model: &CostModel) -> Result<()> {
+ fn put(&self, name: &str, model: &CostModel, results: &Results) -> Result<()> {
self.store.put(
name,
&CacheEntryBorrowed {
lib_hash: self.lib_hash,
model,
+ results,
},
)
}
@@ -120,7 +122,7 @@ fn build_cost_model(results: Results) -> Result<CostModel> {
.into_iter()
.map(|(op, os)| {
debug!("Fitting op {} with {} observations", op, os.len());
- (op, fit::fit(&os))
+ (op, Estimator::fit(&os))
})
.collect(),
})
diff --git a/src/crates/cli/src/main.rs b/src/crates/cli/src/main.rs
index 42bb63d..d779688 100644
--- a/src/crates/cli/src/main.rs
+++ b/src/crates/cli/src/main.rs
@@ -7,13 +7,12 @@ use project::Project;
use crate::{
candidates::CandidatesStore,
- cost::{
- fit::{fit, Estimator},
- ResultsStore,
- },
+ cost::{fit::Estimator, ResultsStore},
paths::Paths,
};
+extern crate nalgebra as na;
+
mod cache;
mod candidates;
mod cost;
@@ -60,7 +59,7 @@ fn main() -> Result<()> {
info!("Found all candidate types. Running benchmarks");
for typ in seen_types.into_iter() {
- let results = benchmarks.get(&typ).context("Error building cost model")?;
+ let results = dbg!(benchmarks.get(&typ).context("Error building cost model")?);
}
Ok(())