// SPDX-FileCopyrightText: 2023 Thomas Kramer // // SPDX-License-Identifier: GPL-3.0-or-later use libreda_logic::truth_table::canonization; use libreda_logic::truth_table::small_lut::*; use criterion::{black_box, criterion_group, criterion_main, Criterion}; /// Benchmark NPN canonization. fn bench_npn_canonization(c: &mut Criterion) { let lut4 = SmallTruthTable::from_table(0xdead, 4); let lut5 = SmallTruthTable::from_table(0xdeadbeef, 5); let lut6 = SmallTruthTable::from_table(0xdeadbeef01234567, 6); c.bench_function("exact_npn_canonization 4", |b| { b.iter(|| canonization::exact_npn_canonization(black_box(lut4))) }); c.bench_function("exact_npn_canonization 5", |b| { b.iter(|| canonization::exact_npn_canonization(black_box(lut5))) }); c.bench_function("exact_npn_canonization 6", |b| { b.iter(|| canonization::exact_npn_canonization(black_box(lut6))) }); // Same but with table sizes known at compile time. let lut4 = SmallStaticTruthTable::<4>::try_from(lut4).unwrap(); let lut5 = SmallStaticTruthTable::<5>::try_from(lut5).unwrap(); let lut6 = SmallStaticTruthTable::<6>::try_from(lut6).unwrap(); c.bench_function("exact_npn_canonization static 4", |b| { b.iter(|| canonization::exact_npn_canonization(black_box(lut4))) }); c.bench_function("exact_npn_canonization static 5", |b| { b.iter(|| canonization::exact_npn_canonization(black_box(lut5))) }); c.bench_function("exact_npn_canonization static 6", |b| { b.iter(|| canonization::exact_npn_canonization(black_box(lut6))) }); } /// Benchmark NN canonization. fn bench_nn_canonization(c: &mut Criterion) { let lut4 = SmallTruthTable::from_table(0xdead, 4); let lut5 = SmallTruthTable::from_table(0xdeadbeef, 5); let lut6 = SmallTruthTable::from_table(0xdeadbeef01234567, 6); c.bench_function("exact_nn_canonization 4", |b| { b.iter(|| canonization::exact_nn_canonization(black_box(lut4))) }); c.bench_function("exact_nn_canonization 5", |b| { b.iter(|| canonization::exact_nn_canonization(black_box(lut5))) }); c.bench_function("exact_nn_canonization 6", |b| { b.iter(|| canonization::exact_nn_canonization(black_box(lut6))) }); } /// Benchmark P canonization. fn bench_p_canonization(c: &mut Criterion) { let lut4 = SmallTruthTable::from_table(0xdead, 4); let lut5 = SmallTruthTable::from_table(0xdeadbeef, 5); let lut6 = SmallTruthTable::from_table(0xdeadbeef01234567, 6); c.bench_function("exact_p_canonization 4", |b| { b.iter(|| canonization::exact_p_canonization(black_box(lut4))) }); c.bench_function("exact_p_canonization 5", |b| { b.iter(|| canonization::exact_p_canonization(black_box(lut5))) }); c.bench_function("exact_p_canonization 6", |b| { b.iter(|| canonization::exact_p_canonization(black_box(lut6))) }); } criterion_group!( benches, bench_npn_canonization, bench_nn_canonization, bench_p_canonization ); criterion_main!(benches);