From 11832b524bf6b1e3a7692dae180399fd744d5ace Mon Sep 17 00:00:00 2001 From: infogulch Date: Tue, 21 Nov 2023 18:12:26 -0600 Subject: [PATCH] Expose inference counts on Machine; publish to CI --- .github/workflows/ci.yml | 1 + benches/setup.rs | 37 +++++++++++++++++++++++++++++++++++-- src/machine/mod.rs | 9 +++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b887d140..9fa463a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -175,6 +175,7 @@ jobs: path: | target/criterion/* target/iai/* + target/benchmark_inference_counts.json # Publish binaries when building for a tag release: diff --git a/benches/setup.rs b/benches/setup.rs index 3102b8c8..5e1fea7c 100644 --- a/benches/setup.rs +++ b/benches/setup.rs @@ -86,14 +86,47 @@ mod test { #[test] fn validate_benchmarks() { 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 = vec![]; - use scryer_prolog::machine::parsed_results::QueryMatch; for (_, r) in prolog_benches() { 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 query_inference_count = machine.get_inference_count() - setup_inference_count; + let expected = QueryResolution::Matches(vec![QueryMatch::from(r.bindings.clone())]); 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"); } } diff --git a/src/machine/mod.rs b/src/machine/mod.rs index 6801575d..b25627db 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -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) { let err = self.machine_st.session_error(err); let stub = functor_stub(key.0, key.1); -- 2.54.0