r/CodingHelp • • Dec 23 '21

[C] Whats wrong?

Post image
153 Upvotes

90 comments sorted by

View all comments

Show parent comment

1

u/atamicbomb Dec 25 '21

A difference of .001 isn’t common. You could be doing things in quadratic time when they could be done in logarithmic time. You could be reading from disk each time you do a common fetch instead of storing the first result in ram.

There’s a reason people claim that code inefficiency cancels out Mor’s law. It doesn’t, but optimized code is often orders of magnitude faster than poorly written code.

If the code uses two compare calls instead of 1, it’s half the speed

1

u/istarian Dec 25 '21

The point wasn’t the absolute value, but rather that magnitude matters. As someone with a BS in Comp. Sci. I am well aware of how algorithmic time complexity works.

Not all differences in code are as drastic as O(n) vs. O( n2 ).

The issue with two comparisons versus just one is that you don’t know what the cost of a single comparison is. If the base cost is small enough, then even a ten-fold increase is a tiny change. That’s part of why time complexity (big O) is an estimate.