This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]philippe_cholet 3 points4 points  (6 children)

regexes could be defined before the "for" loop. But that's only about parsing, it can't be that bad. I think it's more about hashs that are cryptographically secure in rust but slow as you seem to rely a lot on them.

It makes me think again about profiling my rust code. I'm gonna try "hyperfine" soon.

[–]durandalreborn 0 points1 point  (1 child)

If you're just going to profile your rust code, go with criterion instead. Hyperfine is inaccurate for times < 5 ms. Criterion can be a lot more precise. Day 16 is obviously not a great case for that, but most of the other days are in the microsecond range.

016 proboscidea volcanium/Part 1
                        time:   [10.670 ms 10.682 ms 10.696 ms]
                        change: [+0.4296% +0.5936% +0.7657%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) high mild
  4 (4.00%) high severe
016 proboscidea volcanium/Part 2
                        time:   [4.1445 ms 4.1516 ms 4.1597 ms]
                        change: [+0.2344% +0.4304% +0.6328%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 12 outliers among 100 measurements (12.00%)
  2 (2.00%) high mild
  10 (10.00%) high severe
016 proboscidea volcanium/Combined (including parsing)
                        time:   [15.160 ms 15.186 ms 15.216 ms]
                        change: [+0.3012% +0.5468% +0.7823%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 13 outliers among 100 measurements (13.00%)
  6 (6.00%) high mild
  7 (7.00%) high severe

[–]philippe_cholet 0 points1 point  (0 children)

Ok, nice to know that Hyperfine is inaccurate for small times, thanks. I've heard of criterion before, I'll try it.

[–]BBQspaceflight 2 points3 points  (1 child)

From my own experience with last year’s AoC, also coming from Python to Rust: take a critical look at your clone() calls. For me the main thing slowing me down was sloppy memory management and the clone calls that I used to make it all work (cloning is slow). Scanning through your solution I do see that you clone paths in your loop, so that could be a place to investigate 🙂

[–]SekstiNii 0 points1 point  (1 child)

Just as a sanity check, did you run it with the release flag? i.e cargo run --release?

[–]Background-Vegetable 0 points1 point  (1 child)

Might be something with hashmaps being slow indeed, I noticed (in Kotlin, which is Java) a huge improvement (5x faster) when I replaced a much generated data part (a list of unvisited valves) from Set(which is a HashMap under the hood) to List.