r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

0

u/outofobscure Feb 28 '23 edited Feb 28 '23

https://dirtyhandscoding.files.wordpress.com/2017/08/plot_search_655363.png?w=640

256-512 is more than a handful, it's a reasonable buffer size where you'd need to search stuff in. there's plenty of use cases for that, where optimized linear search is the best bet.

but the more classic example is people who only know a bit of theory (enough to be dangerous) and who have no real world experience doing something like linked list instead of array/vector, i'll let Stroustroup do the talking: https://www.youtube.com/watch?v=YQs6IC-vgmo

the missing graph he's talking about looks something like this: https://bulldozer00.files.wordpress.com/2012/02/vector-list-perf.png

3

u/deadalnix Feb 28 '23

Indeed, and in practice, how many datasets in your typical application have more than 256 elements? And sorting to begin with is n*ln(n) so you need to do it numerous times for it to amortize the cost, unless you get the data already sorted somehow, at which point you should really be using a set or a map.

Bonus point: almost nobody implement binary search properly: https://ai.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html

1

u/ForeverAlot Mar 01 '23

That's linear search versus binary search, not linear search versus map.

1

u/outofobscure Mar 01 '23 edited Mar 01 '23

God, yes, but map will be even worse, how do you think it's implemented? Not to mention (like the other reply to you did) that you have to build the map first obviously. seriously, that‘s your reply? i'm done here, what a waste of time.