summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-12-05 19:31:42 +0200
committerLars Wirzenius <liw@liw.fi>2021-12-05 19:31:42 +0200
commit82968fdf4ae02ea6931b0166c519376127723e03 (patch)
treedff55e1b244042e25323e5dd95c7106743a8af1c /src
parentab2c367bc1be514a7eda2c99324366d8d1c63228 (diff)
downloadobnam-benchmark-82968fdf4ae02ea6931b0166c519376127723e03.tar.gz
feat: record name of benchmark for each measurement
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/bin/obnam-benchmark.rs3
-rw-r--r--src/result.rs6
-rw-r--r--src/step.rs8
3 files changed, 12 insertions, 5 deletions
diff --git a/src/bin/obnam-benchmark.rs b/src/bin/obnam-benchmark.rs
index 21012b3..9a326ec 100644
--- a/src/bin/obnam-benchmark.rs
+++ b/src/bin/obnam-benchmark.rs
@@ -53,8 +53,9 @@ impl Run {
fn run(&self) -> anyhow::Result<()> {
let spec = Specification::from_file(&self.spec)?;
let mut result = Result::default();
+ let mut current_benchmark = None;
for step in spec.steps() {
- if let Some(m) = step.execute()? {
+ if let Some(m) = step.execute(&mut current_benchmark)? {
result.push(m);
}
}
diff --git a/src/result.rs b/src/result.rs
index f5d8598..cb23d35 100644
--- a/src/result.rs
+++ b/src/result.rs
@@ -7,6 +7,7 @@ pub struct Result {
#[derive(Debug, Serialize)]
pub struct Measurement {
+ benchmark: String,
op: Operation,
ms: u128,
}
@@ -24,7 +25,8 @@ impl Result {
}
impl Measurement {
- pub fn new(op: Operation, ms: u128) -> Self {
- Self { op, ms }
+ pub fn new(benchmark: &str, op: Operation, ms: u128) -> Self {
+ let benchmark = benchmark.to_string();
+ Self { benchmark, op, ms }
}
}
diff --git a/src/step.rs b/src/step.rs
index 391e7d9..0ca7729 100644
--- a/src/step.rs
+++ b/src/step.rs
@@ -50,14 +50,16 @@ impl Step {
}
}
- pub fn execute(&self) -> Result<Option<Measurement>, StepError> {
+ pub fn execute(&self, current: &mut Option<String>) -> Result<Option<Measurement>, StepError> {
let now = Instant::now();
let op = match self {
Self::Start(name) => {
+ *current = Some(name.to_string());
println!("start benchmark {}", name);
None
}
Self::Stop(name) => {
+ *current = None;
println!("stop benchmark {}", name);
None
}
@@ -88,7 +90,9 @@ impl Step {
let m = if let Some(op) = op {
let ms = now.elapsed().as_millis();
- Some(Measurement::new(op, ms))
+ assert!(current.is_some());
+ let current = current.as_ref().unwrap();
+ Some(Measurement::new(current, op, ms))
} else {
None
};