Benchmark improvements
* CI: Clean offline; display cleaned bytes; one artifact upload * Add missing csv bench to iai benchmarks * Generate flamegraphs for benchmarks * Validate benchmark results separately
This commit is contained in:
@@ -2,7 +2,7 @@ use std::{collections::BTreeMap, fs, path::Path};
|
||||
|
||||
use maplit::btreemap;
|
||||
use scryer_prolog::machine::{
|
||||
parsed_results::{QueryMatch, QueryResolution, Value},
|
||||
parsed_results::{QueryResolution, Value},
|
||||
Machine,
|
||||
};
|
||||
|
||||
@@ -10,20 +10,13 @@ pub fn prolog_benches() -> BTreeMap<&'static str, PrologBenchmark> {
|
||||
[
|
||||
(
|
||||
"count_edges", // name of the benchmark
|
||||
"benches/edges.pl", // name of the prolog module file to load
|
||||
"independent_set_count(aa, Count).", // query to benchmark in the context of the loaded module
|
||||
Strategy::Reuse,
|
||||
btreemap! { "Count" => Value::try_from("211954906".to_string()).unwrap(), }, // list of expected bindings
|
||||
),
|
||||
(
|
||||
"count_edges_short",
|
||||
"benches/edges.pl", // use the same file in multiple benchmarks
|
||||
"independent_set_count(ky, Count).", // consider making the query adjustable to tune the run time to ~0.1s
|
||||
"benches/edges.pl", // name of the prolog module file to load. use the same file in multiple benchmarks
|
||||
"independent_set_count(ky, Count).", // query to benchmark in the context of the loaded module. consider making the query adjustable to tune the run time to ~0.1s
|
||||
Strategy::Reuse,
|
||||
btreemap! { "Count" => Value::try_from("2869176".to_string()).unwrap() },
|
||||
),
|
||||
(
|
||||
"numlist_short",
|
||||
"numlist",
|
||||
"benches/numlist.pl",
|
||||
"run_numlist(1000000, Head).",
|
||||
Strategy::Reuse,
|
||||
@@ -67,27 +60,40 @@ pub struct PrologBenchmark {
|
||||
}
|
||||
|
||||
impl PrologBenchmark {
|
||||
pub fn setup(&self) -> impl FnMut() {
|
||||
pub fn make_machine(&self) -> Machine {
|
||||
let program = fs::read_to_string(self.filename).unwrap();
|
||||
let module_name = Path::new(self.filename)
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap();
|
||||
|
||||
let mut machine = Machine::new_lib();
|
||||
machine.load_module_string(module_name, program);
|
||||
machine
|
||||
}
|
||||
|
||||
let benchmark_name = self.name;
|
||||
pub fn setup(&self) -> impl FnMut() -> QueryResolution {
|
||||
let mut machine = self.make_machine();
|
||||
let query = self.query;
|
||||
let expected = QueryResolution::Matches(vec![QueryMatch::from(self.bindings.clone())]);
|
||||
|
||||
move || {
|
||||
use criterion::black_box;
|
||||
let result = black_box(machine.run_query(black_box(query.to_string())));
|
||||
match result {
|
||||
Ok(r) => assert_eq!(&r, &expected),
|
||||
Err(e) => panic!("benchmark {} failed with: {}", benchmark_name, e),
|
||||
}
|
||||
black_box(machine.run_query(black_box(query.to_string()))).unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn validate_benchmarks() {
|
||||
use super::prolog_benches;
|
||||
use scryer_prolog::machine::parsed_results::QueryResolution;
|
||||
|
||||
use scryer_prolog::machine::parsed_results::QueryMatch;
|
||||
for (_, r) in prolog_benches() {
|
||||
let mut machine = r.make_machine();
|
||||
let result = machine.run_query(r.query.to_string()).unwrap();
|
||||
let expected = QueryResolution::Matches(vec![QueryMatch::from(r.bindings.clone())]);
|
||||
assert_eq!(result, expected, "validating benchmark {}", r.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user