run benchmarks with input

This commit is contained in:
Anton-4 2021-05-28 15:08:46 +02:00
parent 6db9247509
commit 05645088b7
12 changed files with 144 additions and 272 deletions

View file

@ -1,33 +1,15 @@
use crate::helpers::{example_file, run_cmd, run_roc};
use criterion::{BenchmarkGroup, black_box, measurement::{Measurement, WallTime}};
use criterion::{black_box, measurement::Measurement, BenchmarkGroup};
use std::path::Path;
// run without optimization, without input
fn exec_bench_simple(
file: &Path,
executable_filename: &str,
expected_ending: &str,
bench_group_opt: Option<&mut BenchmarkGroup<WallTime>>,
) {
exec_bench_w_input(
file,
"",
executable_filename,
expected_ending,
true,
bench_group_opt,
)
}
fn exec_bench_w_input<T: Measurement>(
file: &Path,
stdin_str: &str,
executable_filename: &str,
expected_ending: &str,
run_optimized: bool,
bench_group_opt: Option<&mut BenchmarkGroup<T>>,
) {
let flags: &[&str] = if run_optimized { &["--optimize"] } else { &[] };
let flags: &[&str] = &["--optimize"];
let compile_out = run_roc(&[&["build", file.to_str().unwrap()], flags].concat());
@ -98,41 +80,44 @@ pub fn bench_nqueens<T: Measurement>(bench_group_opt: Option<&mut BenchmarkGroup
"11",
"nqueens",
"2680\n",
true,
bench_group_opt,
);
}
pub fn bench_cfold(bench_group_opt: Option<&mut BenchmarkGroup<WallTime>>) {
exec_bench_simple(
pub fn bench_cfold<T: Measurement>(bench_group_opt: Option<&mut BenchmarkGroup<T>>) {
exec_bench_w_input(
&example_file("benchmarks", "CFold.roc"),
"12",
"cfold",
"10426 & 10426\n",
bench_group_opt,
);
}
pub fn bench_deriv(bench_group_opt: Option<&mut BenchmarkGroup<WallTime>>) {
exec_bench_simple(
pub fn bench_deriv<T: Measurement>(bench_group_opt: Option<&mut BenchmarkGroup<T>>) {
exec_bench_w_input(
&example_file("benchmarks", "Deriv.roc"),
"7",
"deriv",
"1 count: 6\n2 count: 22\n3 count: 90\n4 count: 420\n5 count: 2202\n6 count: 12886\n7 count: 83648\n",
bench_group_opt,
);
}
pub fn bench_rbtree_ck(bench_group_opt: Option<&mut BenchmarkGroup<WallTime>>) {
exec_bench_simple(
pub fn bench_rbtree_ck<T: Measurement>(bench_group_opt: Option<&mut BenchmarkGroup<T>>) {
exec_bench_w_input(
&example_file("benchmarks", "RBTreeCk.roc"),
"5600",
"rbtree-ck",
"560\n",
bench_group_opt,
);
}
pub fn bench_rbtree_delete(bench_group_opt: Option<&mut BenchmarkGroup<WallTime>>) {
exec_bench_simple(
pub fn bench_rbtree_delete<T: Measurement>(bench_group_opt: Option<&mut BenchmarkGroup<T>>) {
exec_bench_w_input(
&example_file("benchmarks", "RBTreeDel.roc"),
"6000",
"rbtree-del",
"420\n",
bench_group_opt,