2018-10-06 13:28:03 +01:00
|
|
|
#[macro_use]
|
|
|
|
|
extern crate criterion;
|
|
|
|
|
extern crate loot_condition_interpreter;
|
|
|
|
|
|
2018-10-06 15:08:26 +01:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
2018-10-06 13:28:03 +01:00
|
|
|
use criterion::Criterion;
|
|
|
|
|
use loot_condition_interpreter::{Expression, GameType, State};
|
|
|
|
|
|
|
|
|
|
fn generate_active_plugins() -> Vec<String> {
|
2025-07-20 11:33:26 +01:00
|
|
|
let mut vec: Vec<String> = (0..255).map(|i| format!("Blank{i}.esm")).collect();
|
2018-10-06 13:28:03 +01:00
|
|
|
vec.push("Blank.esm".into());
|
|
|
|
|
vec
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn generate_plugin_versions() -> Vec<(String, String)> {
|
|
|
|
|
let mut vec: Vec<(String, String)> = (0..255)
|
2025-07-20 11:33:26 +01:00
|
|
|
.map(|i| (format!("Blank{i}.esm"), "5".to_string()))
|
2018-10-06 13:28:03 +01:00
|
|
|
.collect();
|
|
|
|
|
vec.push(("Blank.esm".into(), "5".into()));
|
|
|
|
|
vec
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn criterion_benchmark(c: &mut Criterion) {
|
|
|
|
|
c.bench_function("Expression.eval() file(path)", |b| {
|
2023-08-18 17:28:00 +01:00
|
|
|
let state = State::new(GameType::Oblivion, ".".into());
|
2018-10-06 15:08:26 +01:00
|
|
|
let expression = Expression::from_str("file(\"Cargo.toml\")").unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.bench_function("Expression.eval() file(regex)", |b| {
|
2023-08-18 17:28:00 +01:00
|
|
|
let state = State::new(GameType::Oblivion, ".".into());
|
2018-10-06 15:08:26 +01:00
|
|
|
let expression = Expression::from_str("file(\"Cargo.*\")").unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.bench_function("Expression.eval() active(path)", |b| {
|
|
|
|
|
let state = State::new(
|
2019-06-25 05:22:58 +01:00
|
|
|
GameType::Oblivion,
|
2018-10-23 18:30:05 +01:00
|
|
|
"tests/testing-plugins/Oblivion/Data".into(),
|
2018-12-22 22:40:16 +00:00
|
|
|
)
|
|
|
|
|
.with_active_plugins(&generate_active_plugins());
|
2018-10-06 13:28:03 +01:00
|
|
|
|
2018-10-06 15:08:26 +01:00
|
|
|
let expression = Expression::from_str("active(\"Blank.esm\")").unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.bench_function("Expression.eval() active(regex)", |b| {
|
|
|
|
|
let state = State::new(
|
2019-06-25 05:22:58 +01:00
|
|
|
GameType::Oblivion,
|
2018-10-23 18:30:05 +01:00
|
|
|
"tests/testing-plugins/Oblivion/Data".into(),
|
2018-12-22 22:40:16 +00:00
|
|
|
)
|
|
|
|
|
.with_active_plugins(&generate_active_plugins());
|
2018-10-06 13:28:03 +01:00
|
|
|
|
2018-10-06 15:08:26 +01:00
|
|
|
let expression = Expression::from_str("active(\"Blank.*\")").unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.bench_function("Expression.eval() many()", |b| {
|
2023-08-18 17:28:00 +01:00
|
|
|
let state = State::new(GameType::Oblivion, ".".into());
|
2018-10-06 15:08:26 +01:00
|
|
|
let expression = Expression::from_str("many(\"Cargo.*\")").unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.bench_function("Expression.eval() many_active()", |b| {
|
|
|
|
|
let state = State::new(
|
2019-06-25 05:22:58 +01:00
|
|
|
GameType::Oblivion,
|
2018-10-23 18:30:05 +01:00
|
|
|
"tests/testing-plugins/Oblivion/Data".into(),
|
2018-12-22 22:40:16 +00:00
|
|
|
)
|
|
|
|
|
.with_active_plugins(&generate_active_plugins());
|
2018-10-06 13:28:03 +01:00
|
|
|
|
2018-10-06 15:08:26 +01:00
|
|
|
let expression = Expression::from_str("many_active(\"Blank.*\")").unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.bench_function("Expression.eval() checksum()", |b| {
|
|
|
|
|
let state = State::new(
|
2019-06-25 05:22:58 +01:00
|
|
|
GameType::Oblivion,
|
2018-10-23 18:30:05 +01:00
|
|
|
"tests/testing-plugins/Oblivion/Data".into(),
|
2018-10-06 13:28:03 +01:00
|
|
|
);
|
2018-10-06 15:08:26 +01:00
|
|
|
let expression = Expression::from_str("checksum(\"Blank.esm\", 374E2A6F)").unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.bench_function("Expression.eval() version(plugin)", |b| {
|
|
|
|
|
let state = State::new(
|
2019-06-25 05:22:58 +01:00
|
|
|
GameType::Oblivion,
|
2018-10-23 18:30:05 +01:00
|
|
|
"tests/testing-plugins/Oblivion/Data".into(),
|
2018-12-22 22:40:16 +00:00
|
|
|
)
|
|
|
|
|
.with_plugin_versions(&generate_plugin_versions());
|
2018-10-06 13:28:03 +01:00
|
|
|
|
2018-10-06 15:08:26 +01:00
|
|
|
let expression = Expression::from_str("version(\"Blank.esm\", \"5.0\", ==)").unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
c.bench_function("Expression.eval() version(executable)", |b| {
|
2023-08-18 17:28:00 +01:00
|
|
|
let state = State::new(GameType::Oblivion, ".".into());
|
2022-11-08 23:06:25 +00:00
|
|
|
let expression =
|
|
|
|
|
Expression::from_str("version(\"tests/libloot_win32/loot.dll\", \"0.18.2.0\", ==)")
|
|
|
|
|
.unwrap();
|
2018-10-06 13:28:03 +01:00
|
|
|
|
|
|
|
|
b.iter(|| {
|
|
|
|
|
assert!(expression.eval(&state).unwrap());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
|
|
|
criterion_main!(benches);
|