rust: Improve benchmarks and optimize day 6 a little
This commit is contained in:
parent
a4dda171b5
commit
ee741775fe
3 changed files with 23 additions and 20 deletions
32
README.md
32
README.md
|
@ -30,7 +30,7 @@ Days 6 and 12 are missing because I did them in IPython and never bothered putti
|
|||
| 22 | | ✔️ | |
|
||||
| 23 | ✔️ | ✔️ | |
|
||||
| 24 | | ✔️ | |
|
||||
| 25 | | | |
|
||||
| 25 | ✔️ | | |
|
||||
|
||||
|
||||
## Benchmarks (Rust)
|
||||
|
@ -39,29 +39,29 @@ I'm somewhat trying to do the <1 second challenge, but I've been a bit short on
|
|||
|
||||
| Day | Time |
|
||||
| ---------: | -----------: |
|
||||
| 1 | 111.14µs |
|
||||
| 2 | 110.91µs |
|
||||
| 3 | 58.66µs |
|
||||
| 4 | 280.38µs |
|
||||
| 5 | 65.60µs |
|
||||
| 6 | - |
|
||||
| 1 | 112.46µs |
|
||||
| 2 | 113.41µs |
|
||||
| 3 | 60.96µs |
|
||||
| 4 | 286.32µs |
|
||||
| 5 | 73.25µs |
|
||||
| 6 | 78.59µs |
|
||||
| 7 | - |
|
||||
| 8 | 168.35µs |
|
||||
| 9 | 45.37µs |
|
||||
| 8 | 170.56µs |
|
||||
| 9 | 46.69µs |
|
||||
| 10 | - |
|
||||
| 11 | - |
|
||||
| 12 | - |
|
||||
| 13 | - |
|
||||
| 14 | - |
|
||||
| 15 | 475441.39µs |
|
||||
| 16 | 338.97µs |
|
||||
| 17 | 69548.73µs |
|
||||
| 15 | 459975.24µs |
|
||||
| 16 | 344.11µs |
|
||||
| 17 | 70782.00µs |
|
||||
| 18 | - |
|
||||
| 19 | 398.30µs |
|
||||
| 19 | 403.49µs |
|
||||
| 20 | - |
|
||||
| 21 | - |
|
||||
| 22 | - |
|
||||
| 23 | 196018.58µs |
|
||||
| 23 | 195819.54µs |
|
||||
| 24 | - |
|
||||
| 25 | 26280.61µs |
|
||||
| **Total:** | 768.867ms |
|
||||
| 25 | 26266.60µs |
|
||||
| **Total:** | 754.533ms |
|
||||
|
|
|
@ -13,7 +13,7 @@ pub fn run(print: bool) -> Duration {
|
|||
let mut part1 = 0;
|
||||
let mut part2 = 0;
|
||||
|
||||
for group in file_string.trim().split("\n\n") {
|
||||
for group in file_string.split("\n\n") {
|
||||
let mut set = 0u32;
|
||||
for c in group.chars().filter(|c| c.is_alphabetic()) {
|
||||
set |= 1 << (c as usize - 'a' as usize);
|
||||
|
@ -29,7 +29,9 @@ pub fn run(print: bool) -> Duration {
|
|||
line_set |= 1 << (c as usize - 'a' as usize);
|
||||
}
|
||||
}
|
||||
if line_set != 0 {
|
||||
set &= line_set;
|
||||
}
|
||||
part2 += count_bits(set);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,12 +73,13 @@ fn main() {
|
|||
}
|
||||
|
||||
let repetitions =
|
||||
5000.min((Duration::new(2, 0).as_nanos() / first_run.as_nanos()) as u32);
|
||||
100000.min((Duration::new(5, 0).as_nanos() / first_run.as_nanos()) as u32);
|
||||
|
||||
let mut elapsed = Duration::new(0, 0);
|
||||
for _ in 0..repetitions {
|
||||
elapsed += days[day](false) / repetitions;
|
||||
elapsed += days[day](false);
|
||||
}
|
||||
elapsed /= repetitions;
|
||||
println!("| {:>2} | {:>10.2}µs |", day + 1, elapsed.as_secs_f64() * 1_000_000.0);
|
||||
total += elapsed;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue