4 ms·
Given that the entire linear chain of comparisons (therefore, every instruction) needs to be evaluated for 2^32-1, it would indeed need to read and execute the
by DHowett 3y ago
Given that the entire linear chain of comparisons (therefore, every instruction) needs to be evaluated for 2^32-1, it would indeed need to read and execute the entire 40GB file.
The fact that it does so by faulting in each page before instructions in it can be executed doesn’t materially avoid having to read every byte.
Clearly the author should have checked the larger numbers first to prevent this (:
- Centigonal 3y agoSoftware development needs to be driven by user needs. Clearly the best action in this scenario is to bundle in telemetry code that reports back which numbers are used with this program, assemble a ranking of the most frequently compared numbers in the real world, and use that to order the comparisons in v2 of the program.
- satiric 3y agoOf course the modern "scaleable" solution is to ask ChatGPT if the number is even or odd, and then print ChatGPT's response.
- constantly 3y agoUsing selenium and chrome webdriver under the hood to do so, as well.
- chrismorgan 3y agoIt’s worth noting that good compilers can actually do a version of this: it’s called profile-guided optimisation <https://en.wikipedia.org/wiki/Profile-guided_optimization https://en.wikipedia.org/wiki/Profile-guided_optimization>. Not many projects use it, because it’s generally a bit of a bother (build a special version, run your profiling, then build everything all over again), but Firefox gets good mileage out of it. My vague recollection is a typical sort of speedup of 5%.
- eviks 3y agoDon't forget to remove the least used 1% of the numbers to make it leaner!
- lmm 3y ago> Given that the entire linear chain of comparisons (therefore, every instruction) needs to be evaluated for 2^32-1, it would indeed need to read and execute the entire 40GB file. It does, but not step by step the way the part I quoted described - the reading from memory can be pipelined with the execution. (And it's an ideal access pattern - reading linearly once - so it wouldn't surprise me if other optimisations kicked in)