4 ms·
> a promise made for pretty much every language ever. Just need a couple of compiler tune ups. Not trying to be critical, that just gave me a chuckle. I was un
by DrJokepu 12y ago
> a promise made for pretty much every language ever. Just need a couple of compiler tune ups. Not trying to be critical, that just gave me a chuckle.
I was under the impression that C's qsort is often beaten by languages with support for templates / generics? I'm pretty sure they were talking about qsort.
- artificialidiot 12y agoIf you compare standard library approaches between languages, yes, ones which let you inline calls will beat callback through pointers in thight loops, which is comparison function in qsort. Most of the time it is inconsequential. You could have used C preprocessor if you really wanted.
- bluecalm 12y agoYeah, but you can easily get C implementations of qsort which beat standard library one on most inputs by 2x/3x. For example here: http://www.ucw.cz/libucw/ http://www.ucw.cz/libucw/. Speed of sorting on modern machines depends mainly on what is in cache so even if you have some very clever implementation (like 3way split in qsort in recent Java) it won't help you if elements are not close to each other in memory. If you are sorting structs vs objects which are somewhere on the heap you already lost the performance battle so the compiler needs to very smart to make up for this.
- erichocean 12y agoso the compiler needs to very smart to make up for this Since compilers don't control malloc, it's pretty hard for them to do any kind of optimization that relies on the physical locations of distinct objects in memory. Not impossible, but even a very smart compiler would find it difficult to do things that an above average programmer could easily do up front, by using a better architecture/approach to begin with.