4 ms·
I think you missed the word "evidence" in my request. I could have predicted that you believed STL was faster. But "it's faster because it's supposed to be fast
by thomasptacek 19y ago
I think you missed the word "evidence" in my request. I could have predicted that you believed STL was faster. But "it's faster because it's supposed to be faster" is a weak argument.
Again I see people in this thread falling into the trap of conflating code reuse, a good thing, with C++, a dubious thing. Code reuse makes things faster, of course; it allows effort to be specialized. But C++ doesn't enable code reuse; it merely encourages it.
- jsjenkins168 19y agoHere are some benchmarks on sorting: http://theory.stanford.edu/~amitp/rants/c++-vs-c/ http://theory.stanford.edu/~amitp/rants/c++-vs-c/ Besides that, custom C vs. STL comparisons would need to be done case-by-case. Admittedly, an all-encompassing statement "STL is always faster than C" is unreasonable. It depends entirely on the situation and what you are trying to do. I'm simply saying that it is very difficult and probably more time consuming than it is worth (for MOST cases) to try to beat STL in C++. When I used to do lots of graphics programming I tried (mostly out of curiosity), but I always ended up just using STL. But maybe your experiences are different? Do you write your own arrays, hash maps, and sorting algorithms each time you use them? There are times when code reuse is A Good Thing. Like when the difference is negligible and it enables you to dedicate time to more valuable things, like building product features that users want. When it comes down to it, everything is always a matter of time. Please explain what you mean when you say "C++ doesnt enable code reuse, it merely encourages it". Just curious..
- thomasptacek 19y agoHe's not using "inline" for the C version, so it counts spurious function call overhead. He's also not holding constant the storage classes between C and C++; his C++ version arbitrarily gets to use optimal storage. This should be intuitive: bare C++ isn't faster than hand-coded C, and beyond that all you can compare is the quality of different libraries. When I say "merely encourages", I'm trying to articulate the fact that most large C projects are composed of modules that implement different ADTs. Just because C doesn't call them "classes" doesn't mean that most C code isn't reusable.