Put benchmarks in own module and added 6MB version of Day 5 problem to see how it performs
This commit is contained in:
parent
3047033aa3
commit
f03ddf12cf
200001
2022/input/5/large
Normal file
200001
2022/input/5/large
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -7,6 +7,7 @@ fn main() -> Result<()> {
|
||||||
Day::solve()
|
Day::solve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- Tests --
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -27,17 +28,23 @@ mod tests {
|
||||||
fn part2_solution() -> Result<()> {
|
fn part2_solution() -> Result<()> {
|
||||||
Day::test(aoc::Part::TWO, "input", 206582)
|
Day::test(aoc::Part::TWO, "input", 206582)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Benchmarks --
|
||||||
|
#[cfg(test)]
|
||||||
|
mod bench {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
// Benchmarks
|
// Benchmarks
|
||||||
extern crate test;
|
extern crate test;
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part1_bench(b: &mut test::Bencher) {
|
fn part1_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::ONE, b)
|
Day::benchmark(aoc::Part::ONE, b)
|
||||||
}
|
}
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part2_bench(b: &mut test::Bencher) {
|
fn part2_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::TWO, b)
|
Day::benchmark(aoc::Part::TWO, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,17 +27,23 @@ mod tests {
|
||||||
fn part2_solution() -> Result<()> {
|
fn part2_solution() -> Result<()> {
|
||||||
Day::test(aoc::Part::TWO, "input", 12382)
|
Day::test(aoc::Part::TWO, "input", 12382)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Benchmarks --
|
||||||
|
#[cfg(test)]
|
||||||
|
mod bench {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
// Benchmarks
|
// Benchmarks
|
||||||
extern crate test;
|
extern crate test;
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part1_bench(b: &mut test::Bencher) {
|
fn part1_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::ONE, b)
|
Day::benchmark(aoc::Part::ONE, b)
|
||||||
}
|
}
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part2_bench(b: &mut test::Bencher) {
|
fn part2_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::TWO, b)
|
Day::benchmark(aoc::Part::TWO, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,17 +27,23 @@ mod tests {
|
||||||
fn part2_solution() -> Result<()> {
|
fn part2_solution() -> Result<()> {
|
||||||
Day::test(aoc::Part::TWO, "input", 2708)
|
Day::test(aoc::Part::TWO, "input", 2708)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Benchmarks --
|
||||||
|
#[cfg(test)]
|
||||||
|
mod bench {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
// Benchmarks
|
// Benchmarks
|
||||||
extern crate test;
|
extern crate test;
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part1_bench(b: &mut test::Bencher) {
|
fn part1_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::ONE, b)
|
Day::benchmark(aoc::Part::ONE, b)
|
||||||
}
|
}
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part2_bench(b: &mut test::Bencher) {
|
fn part2_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::TWO, b)
|
Day::benchmark(aoc::Part::TWO, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,17 +28,23 @@ mod tests {
|
||||||
fn part2_solution() -> Result<()> {
|
fn part2_solution() -> Result<()> {
|
||||||
Day::test(aoc::Part::TWO, "input", 907)
|
Day::test(aoc::Part::TWO, "input", 907)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Benchmarks --
|
||||||
|
#[cfg(test)]
|
||||||
|
mod bench {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
// Benchmarks
|
// Benchmarks
|
||||||
extern crate test;
|
extern crate test;
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part1_bench(b: &mut test::Bencher) {
|
fn part1_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::ONE, b)
|
Day::benchmark(aoc::Part::ONE, b)
|
||||||
}
|
}
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part2_bench(b: &mut test::Bencher) {
|
fn part2_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::TWO, b)
|
Day::benchmark(aoc::Part::TWO, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ fn main() -> Result<()> {
|
||||||
Day::solve()
|
Day::solve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -- Tests --
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -33,16 +34,35 @@ mod tests {
|
||||||
Day::test(aoc::Part::TWO, "input", "CNSFCGJSM".to_string())
|
Day::test(aoc::Part::TWO, "input", "CNSFCGJSM".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run it on a 6MB file to see how it performs
|
||||||
|
// https://www.reddit.com/r/adventofcode/comments/zd1hqy/2022_day_5_i_know_i_am_overthinking_it/iyzvsnp/?context=3
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn part1_large() -> Result<()> {
|
||||||
|
Day::test(aoc::Part::ONE, "large", "GATHERING".to_string())
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn part2_large() -> Result<()> {
|
||||||
|
Day::test(aoc::Part::TWO, "large", "DEVSCHUUR".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Benchmarks --
|
||||||
|
#[cfg(test)]
|
||||||
|
mod bench {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
// Benchmarks
|
// Benchmarks
|
||||||
extern crate test;
|
extern crate test;
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part1_bench(b: &mut test::Bencher) {
|
fn part1_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::ONE, b)
|
Day::benchmark(aoc::Part::ONE, b)
|
||||||
}
|
}
|
||||||
#[bench]
|
#[bench]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn part2_bench(b: &mut test::Bencher) {
|
fn part2_solution(b: &mut test::Bencher) {
|
||||||
Day::benchmark(aoc::Part::TWO, b)
|
Day::benchmark(aoc::Part::TWO, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +157,7 @@ fn parse_instruction(s: &str) -> (usize, usize, usize) {
|
||||||
(amount, from, to)
|
(amount, from, to)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn solution(input: &str, reverse: bool) -> String {
|
fn solution(input: &str, part1: bool) -> String {
|
||||||
// The current layout description ends with an empty line
|
// The current layout description ends with an empty line
|
||||||
let mut boat = Boat::new(&input
|
let mut boat = Boat::new(&input
|
||||||
.lines()
|
.lines()
|
||||||
|
@ -151,9 +171,9 @@ fn solution(input: &str, reverse: bool) -> String {
|
||||||
.map(parse_instruction)
|
.map(parse_instruction)
|
||||||
.for_each(|(amount, from, to)| {
|
.for_each(|(amount, from, to)| {
|
||||||
let mut taken = boat.take(from, amount);
|
let mut taken = boat.take(from, amount);
|
||||||
// The order needs to be reversed in part due to the crates being moves one at the time
|
if part1 {
|
||||||
// instead of the whole stack at once as happens in part 2
|
// In part one we move the crates on by one, so the vector needs to be reverse to
|
||||||
if reverse {
|
// get the correct order
|
||||||
taken.reverse();
|
taken.reverse();
|
||||||
}
|
}
|
||||||
boat.put(to, taken);
|
boat.put(to, taken);
|
||||||
|
|
|
@ -47,9 +47,9 @@ pub trait Solver {
|
||||||
|
|
||||||
fn benchmark(part: Part, b: &mut test::Bencher) {
|
fn benchmark(part: Part, b: &mut test::Bencher) {
|
||||||
let f = Self::select(part);
|
let f = Self::select(part);
|
||||||
|
let input = fs::read_to_string(format!("input/{}/input", Self::day())).with_context(|| format!("Failed to read 'input' for day {}", Self::day())).unwrap();
|
||||||
|
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let input = fs::read_to_string(format!("input/{}/input", Self::day())).unwrap();
|
|
||||||
f(&input)
|
f(&input)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user