3 ms·
It depends on the compiler really. C is nice is that you can choose a compiler fit for your purpose but it makes my next example harder to I'm going to discuss
by 6D794163636F756 3y ago
It depends on the compiler really. C is nice is that you can choose a compiler fit for your purpose but it makes my next example harder to I'm going to discuss go. I was doing leetcode recently and one of the problems was to combine some set of sorted linked arrays into one bigger array. There are a few ways to do this but I ran two of them to see which was better.
1.) I select the lowest from the set of first elements in the arrays, add it to the end of my new list, then increment the iterator for that array.
2.) Dump all of them into one array then sort the new array entirely.
Surprisingly the second option was faster and didn't have a higher memory cost. From what I could tell this was because it used fewer memory allocations, could run better optimizations, and the standard library in go has a good sorting algorithm. One of the greatest skills I think we can develop as programmers is knowing when to trust the compiler and when not to.
All of this is to say I agree with you on principle but there is nuance and a degree to which we can trust the compiler, but only if we've chosen one that we are familiar with and that is well suited for the task at hand.
- almostnormal 3y agoNot necessarily just a matter of details of the assembly, but also of cache utilization.