Comment

Comment by MattPalmer1086

Benchmarking is just insanely hard to do well. There are so many things which can mislead you.

I recently discovered a way to make an algorithm about 15% faster. At least, that's what all the benchmarks said. At some point I duplicated the faster function in my test harness, but did not call the faster version, just the original slower one... And it was still 15% faster. So code that never executed sped up the original code...!!! Obviously, this was due to code and memory layout issues, moving something so it aligned with some CPU cache better.

It's actually really really hard to know if speedups you get are because your code is actually "better" or just because you lucked out with some better alignment somewhere.

Casey Muratori has a really interesting series about things like this in his substack.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton