Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 125 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ debug = false
strip = true

[profile.bench]
inherits = "release-minimal"
inherits = "release"
8 changes: 6 additions & 2 deletions nemo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ ascii_tree = { workspace = true }
async-trait = { workspace = true }
serde_json = { workspace = true }
serde = { workspace = true, features = ["derive"] }
nom-greedyerror = "0.5.0"
nom-supreme = "0.8.0"
smallvec = "1.15"
enum-assoc = "1.1.0"
ariadne = { workspace = true, features = ["auto-color"] }
strum = { workspace = true }
Expand All @@ -63,4 +62,9 @@ env_logger = { workspace = true }
assert_fs = { workspace = true }
test-log = { workspace = true }
tokio = { workspace = true, features = [ "rt", "macros" ] }
criterion = { version = "0.8.2", default-features = false, features = [ "cargo_bench_support" ] }

[[bench]]
name = "parser"
harness = false

53 changes: 53 additions & 0 deletions nemo/benches/parser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! Benchmarks for the parser and the AST-to-rule-model translation.

use criterion::{Criterion, Throughput, criterion_group, criterion_main};
use nemo::{parser::Parser, rule_file::RuleFile, rule_model::programs::handle::ProgramHandle};
use std::hint::black_box;

/// Program consisting of many rules, each joining many atoms.
const RULES: &str = include_str!("../../resources/benchmarks/variable-order-stress.rls");
/// Program consisting of many ground facts.
const FACTS: &str = include_str!("../../resources/benchmarks/fact-stress.rls");

/// Parse the given program, discarding the result.
fn parse(input: &str) {
let parser = Parser::initialize(input);
let _ = black_box(parser.parse());
}

/// Parse the given program and translate it into the rule model.
fn parse_and_translate(input: &str) {
let file = RuleFile::new(input.to_owned(), String::from("bench"));
let _ = black_box(ProgramHandle::from_file(&file));
}

/// Number of samples per benchmark.
const SAMPLE_SIZE: usize = 10;

fn benchmark_parse(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("parse");
group.sample_size(SAMPLE_SIZE);

group.throughput(Throughput::Bytes(RULES.len() as u64));
group.bench_function("rules", |bencher| bencher.iter(|| parse(black_box(RULES))));

group.throughput(Throughput::Bytes(FACTS.len() as u64));
group.bench_function("facts", |bencher| bencher.iter(|| parse(black_box(FACTS))));

group.finish();
}

fn benchmark_translate(criterion: &mut Criterion) {
let mut group = criterion.benchmark_group("parse+translate");
group.sample_size(SAMPLE_SIZE);

group.throughput(Throughput::Bytes(RULES.len() as u64));
group.bench_function("rules", |bencher| {
bencher.iter(|| parse_and_translate(black_box(RULES)))
});

group.finish();
}

criterion_group!(benches, benchmark_parse, benchmark_translate);
criterion_main!(benches);
Loading