Addressed comments on benchmarking PR
This commit is contained in:
@@ -304,7 +304,6 @@ where
|
||||
seed: u32,
|
||||
times_to_run: usize,
|
||||
env: Option<String>,
|
||||
output: PathBuf,
|
||||
) -> Result<(), Vec<Error>> {
|
||||
let options = Options {
|
||||
tracing: Tracing::silent(),
|
||||
@@ -314,7 +313,6 @@ where
|
||||
exact_match,
|
||||
seed,
|
||||
times_to_run,
|
||||
output,
|
||||
},
|
||||
blueprint_path: self.blueprint_path(None),
|
||||
};
|
||||
@@ -427,7 +425,7 @@ where
|
||||
seed,
|
||||
property_max_success,
|
||||
} => {
|
||||
let tests = self.collect_tests(false, match_tests, exact_match, options.tracing)?;
|
||||
let tests = self.collect_tests(verbose, match_tests, exact_match, options.tracing)?;
|
||||
|
||||
if !tests.is_empty() {
|
||||
self.event_listener.handle_event(Event::RunningTests);
|
||||
@@ -471,9 +469,7 @@ where
|
||||
exact_match,
|
||||
seed,
|
||||
times_to_run,
|
||||
output,
|
||||
} => {
|
||||
// todo - collect benchmarks
|
||||
let tests =
|
||||
self.collect_benchmarks(false, match_tests, exact_match, options.tracing)?;
|
||||
|
||||
@@ -496,51 +492,12 @@ where
|
||||
|
||||
self.event_listener.handle_event(Event::FinishedBenchmarks {
|
||||
seed,
|
||||
tests: tests.clone(),
|
||||
tests,
|
||||
});
|
||||
|
||||
if !errors.is_empty() {
|
||||
Err(errors)
|
||||
} else {
|
||||
// Write benchmark results to CSV
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
let mut writer = File::create(&output).map_err(|error| {
|
||||
vec![Error::FileIo {
|
||||
error,
|
||||
path: output.clone(),
|
||||
}]
|
||||
})?;
|
||||
|
||||
// Write CSV header
|
||||
writeln!(writer, "test_name,module,memory,cpu").map_err(|error| {
|
||||
vec![Error::FileIo {
|
||||
error,
|
||||
path: output.clone(),
|
||||
}]
|
||||
})?;
|
||||
|
||||
// Write benchmark results
|
||||
for test in tests {
|
||||
if let TestResult::Benchmark(result) = test {
|
||||
writeln!(
|
||||
writer,
|
||||
"{},{},{},{}",
|
||||
result.test.name,
|
||||
result.test.module,
|
||||
result.cost.mem,
|
||||
result.cost.cpu
|
||||
)
|
||||
.map_err(|error| {
|
||||
vec![Error::FileIo {
|
||||
error,
|
||||
path: output.clone(),
|
||||
}]
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ pub enum CodeGenMode {
|
||||
exact_match: bool,
|
||||
seed: u32,
|
||||
times_to_run: usize,
|
||||
output: PathBuf,
|
||||
},
|
||||
NoOp,
|
||||
}
|
||||
|
||||
@@ -135,7 +135,6 @@ pub(crate) fn find_max_execution_units<T>(xs: &[TestResult<T, T>]) -> (usize, us
|
||||
}
|
||||
}
|
||||
TestResult::Benchmark(..) => {
|
||||
// todo riley - should this be reachable?
|
||||
unreachable!("property returned benchmark result ?!")
|
||||
}
|
||||
});
|
||||
|
||||
@@ -39,6 +39,30 @@ impl EventListener for Json {
|
||||
});
|
||||
println!("{}", serde_json::to_string_pretty(&json_output).unwrap());
|
||||
}
|
||||
Event::FinishedBenchmarks { tests, seed } => {
|
||||
let benchmark_results: Vec<_> = tests
|
||||
.into_iter()
|
||||
.filter_map(|test| {
|
||||
if let TestResult::Benchmark(result) = test {
|
||||
Some(serde_json::json!({
|
||||
"name": result.test.name,
|
||||
"module": result.test.module,
|
||||
"memory": result.cost.mem,
|
||||
"cpu": result.cost.cpu
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let json = serde_json::json!({
|
||||
"benchmarks": benchmark_results,
|
||||
"seed": seed,
|
||||
});
|
||||
|
||||
println!("{}", serde_json::to_string_pretty(&json).unwrap());
|
||||
}
|
||||
_ => super::Terminal.handle_event(event),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,14 +224,19 @@ impl EventListener for Terminal {
|
||||
"...".if_supports_color(Stderr, |s| s.bold())
|
||||
);
|
||||
}
|
||||
Event::FinishedBenchmarks { seed: _, tests: _ } => {
|
||||
eprintln!(
|
||||
"{} {}",
|
||||
" Complete"
|
||||
.if_supports_color(Stderr, |s| s.bold())
|
||||
.if_supports_color(Stderr, |s| s.green()),
|
||||
"benchmark results written to CSV".if_supports_color(Stderr, |s| s.bold())
|
||||
);
|
||||
Event::FinishedBenchmarks { tests, .. } => {
|
||||
for test in tests {
|
||||
if let TestResult::Benchmark(result) = test {
|
||||
println!(
|
||||
"{} {} ",
|
||||
result.test.name.bold(),
|
||||
"BENCH".blue(),
|
||||
);
|
||||
println!(" Memory: {} bytes", result.cost.mem);
|
||||
println!(" CPU: {} units", result.cost.cpu);
|
||||
println!();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,7 +289,6 @@ mod test {
|
||||
result.labels
|
||||
)
|
||||
}
|
||||
// todo riley - should this be reachable?
|
||||
TestResult::Benchmark(..) => unreachable!("property returned benchmark result ?!"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user