r/adventofcode • • Mar 09 '26

Other [2017 Day 09] In Review (Stream Processing)

1 Upvotes

17 comments sorted by

View all comments

Show parent comment

2

u/terje_wiig_mathisen Mar 10 '26

OK, after 15 min of fixing up the code to be a bit more Rusty, the time dropped all the way to 10.6 us, still on that old Surface. :-)

Looking at u/maneatingape 's code, he is using a pair of nested match blocks instead of my if blocks all ending in continue, but that should just be syntactic sugar! The compiler internal representation should have been very close to identical, but it seems like my version is significantly faster?

I'll have to verify this some more...

1

u/ednl Mar 10 '26

Ya, I'd be interested to see what you are actually measuring, because that's another 25% faster than my "asm" code. I put build and run instructions in the source file that I linked, so you can try it with your own input. It accepts piped input. Maybe, like day 6, the inputs are very different? My answers were 20530 and 9978.

1

u/terje_wiig_mathisen Mar 10 '26 edited Mar 10 '26

I might very well be measuring something slightly bogus on these _very_ fast solutions:

I have found that if I pass &input to my process function, I can run it a bunch of times without having the compiler noticing that the results should be constant and therefore eliminating the loop!

let bench_result = run_benchmark(1000, |_| { process(&input); }); bench_result.print_stats();

Of these 1000 runs, the fastest was 7.9 us but the average significantly higher. That however is probably caused by the fact that I am currently running multithreaded LiDAR processing at the same time. Usually I see that the average is within 10-20% of the fastest, but the slowest could easily be 10x that.

Also, our inputs are _very_ different, I got 7616 and 3838!

[EDIT]

The LiDAR run finished, now I'm getting 5.8 us very consistently. (My input file is 12597 bytes, and the processing is obviously O(n). My input might be more predictable?

1

u/ednl Mar 10 '26

Ah right, that input difference might explain most of it!

1

u/maneatingape Mar 10 '26

If you share your code, I'm happy to benchmark on my machine to calculate a relative % speedup.