66 lines
1.9 KiB
Rust
66 lines
1.9 KiB
Rust
#[macro_use]
|
|
extern crate criterion;
|
|
extern crate adversary;
|
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
|
|
fn vm(c: &mut Criterion) {
|
|
let expression =
|
|
adversary::vm::parsing::parse_relation("and (= (ham (^ x y)) (ham (+ 3 x))) (> (* x y) 5)");
|
|
if let Err(e) = expression {
|
|
println!("{}", e);
|
|
panic!();
|
|
}
|
|
let code = adversary::vm::compile_boolean(expression.unwrap());
|
|
let mut stack = adversary::vm::VmStack::from_code(&code);
|
|
c.bench_function("vm", |b| {
|
|
b.iter(|| {
|
|
for x in 0..(1 << 6) {
|
|
for y in 0..(1 << 6) {
|
|
criterion::black_box(
|
|
adversary::vm::Vm::load(
|
|
&code,
|
|
adversary::vm::Registers::load(x, y, 6, 0, 0),
|
|
&mut stack,
|
|
)
|
|
.run(),
|
|
);
|
|
}
|
|
}
|
|
})
|
|
});
|
|
}
|
|
|
|
fn search(c: &mut Criterion) {
|
|
pyo3::prepare_freethreaded_python();
|
|
pyo3::Python::with_gil(|_py| {
|
|
let obj = adversary::Prover::py_new(
|
|
"= (ham x) k".to_string(),
|
|
"= (ham y) (+ k 1)".to_string(),
|
|
"<= ham (^ x y) p".to_string(),
|
|
)
|
|
.unwrap();
|
|
c.bench_function("search", |b| {
|
|
b.iter(|| criterion::black_box(obj.find_bounds(10, 5, 3)));
|
|
});
|
|
})
|
|
}
|
|
|
|
fn search_big(c: &mut Criterion) {
|
|
pyo3::prepare_freethreaded_python();
|
|
pyo3::Python::with_gil(|_py| {
|
|
let obj = adversary::Prover::py_new(
|
|
"= (ham x) k".to_string(),
|
|
"= (ham y) (+ k 1)".to_string(),
|
|
"<= ham (^ x y) p".to_string(),
|
|
)
|
|
.unwrap();
|
|
c.bench_function("search_big", |b| {
|
|
b.iter(|| criterion::black_box(obj.find_bounds(12, 5, 8)));
|
|
});
|
|
})
|
|
}
|
|
|
|
criterion_group!(benches, vm, search, search_big);
|
|
criterion_main!(benches);
|