Initial work on writing benchmarks.

This commit is contained in:
2018-12-18 13:56:34 +01:00
parent 33f32fc1ac
commit cc72c481cc
2 changed files with 56 additions and 0 deletions

View File

@@ -9,3 +9,10 @@ clap = "2.32"
regex = "1.1.0" regex = "1.1.0"
chrono = "0.4.6" chrono = "0.4.6"
itertools = "0.7.11" itertools = "0.7.11"
[dev-dependencies]
bencher = "0.1.5"
[[bench]]
name = "days"
harness = false

49
2018/benches/days.rs Normal file
View File

@@ -0,0 +1,49 @@
extern crate aoc_2018;
#[macro_use]
extern crate bencher;
use bencher::Bencher;
use aoc_2018::get_impl;
const INPUTS: &[&[u8]] = &[
include_bytes!("../inputs/01.txt"),
include_bytes!("../inputs/02.txt"),
];
fn test_part1(day: u32, bench: &mut Bencher) {
bench.iter(|| {
let input = INPUTS[day as usize - 1];
let mut instance = get_impl(day);
instance.part1(&mut input.as_ref())
})
}
fn test_part2(day: u32, bench: &mut Bencher) {
bench.iter(|| {
let input = INPUTS[day as usize - 1];
let mut instance = get_impl(day);
instance.part2(&mut input.as_ref())
})
}
fn day1_part1(bench: &mut Bencher) {
test_part1(1, bench)
}
fn day1_part2(bench: &mut Bencher) {
test_part2(1, bench)
}
fn day2_part1(bench: &mut Bencher) {
test_part1(2, bench)
}
fn day2_part2(bench: &mut Bencher) {
test_part2(2, bench)
}
benchmark_group!(day1, day1_part1, day1_part2);
benchmark_group!(day2, day2_part1, day2_part2);
benchmark_main!(day1, day2);