mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Compare commits
2 Commits
0897e2e907
...
07cbf6cf53
| Author | SHA1 | Date | |
|---|---|---|---|
| 07cbf6cf53 | |||
| 6e3252ce5a |
@@ -9,6 +9,13 @@ clap = { version = "3.0.0-rc.0", features = ["derive"] }
|
|||||||
itertools = "0.10"
|
itertools = "0.10"
|
||||||
nom = "7"
|
nom = "7"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = "0.3"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
# Keep debug information in release for better flamegraphs
|
# Keep debug information in release for better flamegraphs
|
||||||
debug = true
|
debug = true
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "days"
|
||||||
|
harness = false
|
||||||
|
|||||||
42
2021/benches/days.rs
Normal file
42
2021/benches/days.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
use aoc_2021::get_implementation;
|
||||||
|
use criterion::criterion_group;
|
||||||
|
use criterion::criterion_main;
|
||||||
|
use criterion::BenchmarkId;
|
||||||
|
use criterion::Criterion;
|
||||||
|
|
||||||
|
const DAYS_IMPLEMENTED: usize = 12;
|
||||||
|
|
||||||
|
fn read_input(day: usize) -> Vec<u8> {
|
||||||
|
let input_path = format!("inputs/{:02}.txt", day);
|
||||||
|
|
||||||
|
let mut buffer = Vec::new();
|
||||||
|
File::open(input_path)
|
||||||
|
.expect("Failed to open input file")
|
||||||
|
.read_to_end(&mut buffer)
|
||||||
|
.expect("Failed to read input file");
|
||||||
|
|
||||||
|
buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn benchmark_days(c: &mut Criterion) {
|
||||||
|
for day in 1..=DAYS_IMPLEMENTED {
|
||||||
|
let input = read_input(day);
|
||||||
|
|
||||||
|
let part1 = get_implementation(day, false);
|
||||||
|
let part2 = get_implementation(day, true);
|
||||||
|
|
||||||
|
c.bench_with_input(BenchmarkId::new("part1", day), &input, |b, i| {
|
||||||
|
b.iter(|| part1(&mut &i[..]));
|
||||||
|
});
|
||||||
|
|
||||||
|
c.bench_with_input(BenchmarkId::new("part2", day), &input, |b, i| {
|
||||||
|
b.iter(|| part2(&mut &i[..]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, benchmark_days);
|
||||||
|
criterion_main!(benches);
|
||||||
@@ -13,7 +13,7 @@ fn parse_input(input: &mut dyn Read) -> Vec<(Dir, i32)> {
|
|||||||
let mut moves = Vec::new();
|
let mut moves = Vec::new();
|
||||||
|
|
||||||
while let Some(line) = reader.next() {
|
while let Some(line) = reader.next() {
|
||||||
let (dir, amount) = line.split_once(" ").unwrap();
|
let (dir, amount) = line.split_once(' ').unwrap();
|
||||||
|
|
||||||
let dir = match dir {
|
let dir = match dir {
|
||||||
"up" => Dir::Up,
|
"up" => Dir::Up,
|
||||||
|
|||||||
Reference in New Issue
Block a user