Expose inference counts on Machine; publish to CI
This commit is contained in:
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@@ -175,6 +175,7 @@ jobs:
|
|||||||
path: |
|
path: |
|
||||||
target/criterion/*
|
target/criterion/*
|
||||||
target/iai/*
|
target/iai/*
|
||||||
|
target/benchmark_inference_counts.json
|
||||||
|
|
||||||
# Publish binaries when building for a tag
|
# Publish binaries when building for a tag
|
||||||
release:
|
release:
|
||||||
|
|||||||
@@ -86,14 +86,47 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn validate_benchmarks() {
|
fn validate_benchmarks() {
|
||||||
use super::prolog_benches;
|
use super::prolog_benches;
|
||||||
use scryer_prolog::machine::parsed_results::QueryResolution;
|
use scryer_prolog::machine::parsed_results::{QueryMatch, QueryResolution};
|
||||||
|
use std::{fmt::Write, fs};
|
||||||
|
|
||||||
|
struct BenchResult {
|
||||||
|
pub name: &'static str,
|
||||||
|
pub setup_inference_count: u64,
|
||||||
|
pub query_inference_count: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut results: Vec<BenchResult> = vec![];
|
||||||
|
|
||||||
use scryer_prolog::machine::parsed_results::QueryMatch;
|
|
||||||
for (_, r) in prolog_benches() {
|
for (_, r) in prolog_benches() {
|
||||||
let mut machine = r.make_machine();
|
let mut machine = r.make_machine();
|
||||||
|
let setup_inference_count = machine.get_inference_count();
|
||||||
|
|
||||||
let result = machine.run_query(r.query.to_string()).unwrap();
|
let result = machine.run_query(r.query.to_string()).unwrap();
|
||||||
|
let query_inference_count = machine.get_inference_count() - setup_inference_count;
|
||||||
|
|
||||||
let expected = QueryResolution::Matches(vec![QueryMatch::from(r.bindings.clone())]);
|
let expected = QueryResolution::Matches(vec![QueryMatch::from(r.bindings.clone())]);
|
||||||
assert_eq!(result, expected, "validating benchmark {}", r.name);
|
assert_eq!(result, expected, "validating benchmark {}", r.name);
|
||||||
|
|
||||||
|
results.push(BenchResult {
|
||||||
|
name: r.name,
|
||||||
|
setup_inference_count,
|
||||||
|
query_inference_count,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut json: String = Default::default();
|
||||||
|
json.push('[');
|
||||||
|
for r in results {
|
||||||
|
json.push('\n');
|
||||||
|
write!(
|
||||||
|
json,
|
||||||
|
r#"{{"name":"{}","setup_inference_count":{},"query_inference_count":{}}},"#,
|
||||||
|
r.name, r.setup_inference_count, r.query_inference_count
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
json.pop(); // trailing comma
|
||||||
|
json.push_str("\n]");
|
||||||
|
fs::write("target/benchmark_inference_counts.json", json).expect("Unable to write file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,6 +211,15 @@ impl Machine {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_inference_count(&mut self) -> u64 {
|
||||||
|
self.machine_st
|
||||||
|
.cwil
|
||||||
|
.global_count
|
||||||
|
.clone()
|
||||||
|
.try_into()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn throw_session_error(&mut self, err: SessionError, key: PredicateKey) {
|
pub fn throw_session_error(&mut self, err: SessionError, key: PredicateKey) {
|
||||||
let err = self.machine_st.session_error(err);
|
let err = self.machine_st.session_error(err);
|
||||||
let stub = functor_stub(key.0, key.1);
|
let stub = functor_stub(key.0, key.1);
|
||||||
|
|||||||
Reference in New Issue
Block a user