mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 05:40:32 +01:00
Faster hash set
This commit is contained in:
@@ -10,34 +10,31 @@ use criterion::Criterion;
|
||||
/// Number of days we have an implementation to benchmark
|
||||
const DAYS_IMPLEMENTED: u8 = 25;
|
||||
|
||||
fn read_input(day: u8) -> Vec<u8> {
|
||||
fn read_input(day: u8) -> std::io::Result<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");
|
||||
File::open(input_path)?.read_to_end(&mut buffer)?;
|
||||
|
||||
buffer
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
pub fn benchmark_days(c: &mut Criterion) {
|
||||
for day in 1..=DAYS_IMPLEMENTED {
|
||||
let input = read_input(day);
|
||||
if let Ok(input) = read_input(day) {
|
||||
let part1 = get_implementation(day, false).unwrap();
|
||||
|
||||
let part1 = get_implementation(day, false).unwrap();
|
||||
|
||||
c.bench_with_input(BenchmarkId::new("part1", day), &input, |b, i| {
|
||||
b.iter(|| part1(i));
|
||||
});
|
||||
|
||||
if day < 25 {
|
||||
let part2 = get_implementation(day, true).unwrap();
|
||||
|
||||
c.bench_with_input(BenchmarkId::new("part2", day), &input, |b, i| {
|
||||
b.iter(|| part2(i));
|
||||
c.bench_with_input(BenchmarkId::new("part1", day), &input, |b, i| {
|
||||
b.iter(|| part1(i));
|
||||
});
|
||||
|
||||
if day < 25 {
|
||||
let part2 = get_implementation(day, true).unwrap();
|
||||
|
||||
c.bench_with_input(BenchmarkId::new("part2", day), &input, |b, i| {
|
||||
b.iter(|| part2(i));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user