suiron/
benchmark.rs

1//! Module for benchmarking.
2//!
3//! This module performs a Q sort on a list of numbers, in order
4//! to measure the speed of the inference engine, and to compare
5//! it with other implementations.
6//!
7//! Run the following command from the CLI:
8//! <pre>
9//! > cargo bench
10//! </pre>
11//
12// Other potentially useful commands.
13// > sudo cargo profile cpu per-fn bench --bench suiron_benchmark
14// > sudo cargo flamegraph --bench suiron_benchmark
15//
16// Cleve Lendon 2023
17
18use std::process;
19use std::rc::Rc;
20
21use super::goal::*;
22use super::s_complex::*;
23use super::solutions::*;
24use super::rule_reader::*;
25use super::knowledge_base::*;
26
27/// Reads in a qsort algorithm and data from a file, then runs the algorithm.
28///
29pub fn benchmark() {
30
31    let file_path = "./tests/qsort.txt";
32    //println!("Loading file: {}", file_path);
33
34    let mut kb = KnowledgeBase::new();
35    let result = load_kb_from_file(&mut kb, &file_path);
36    match result {
37        Some(err) => {
38            println!("{}", err);
39            process::exit(0);
40        },
41        None => {}, // All OK.
42    }
43    //print_kb(&kb); // For debugging.
44
45    let input = "m";
46    let query = parse_query(&input);
47    match query {
48        Ok(q) => {
49            let sn = make_base_node(Rc::new(q), &kb); // solution node
50            let result = solve(Rc::clone(&sn));
51            print!("{} ", result);
52        },
53        Err(err) => { println!("{}", err); },
54    } // match
55
56}  // benchmark