3 ms·
I haven't (yet) read the article, but let me provide an anecdote to answer the question posed by the post title "Is C++ fast?": I write in C++. I had a coworke
by inetknght 8y ago
I haven't (yet) read the article, but let me provide an anecdote to answer the question posed by the post title "Is C++ fast?":
I write in C++. I had a coworker who wrote in Ruby. He wanted to learn C++ because C++ is "fast". So he wrote two identical programs: one in C++ and one in Ruby. Then, he ran both programs though `time` to determine how long each took.
His C++ program took longer.
Why was that?
He didn't write his C++ program using any efficient algorithms whatsoever while his Ruby program was well-designed. He came to me to try to tell me that C++ wasn't as fast as Ruby.
So I rewrote his C++ program. My C++ program then ran almost instantly while his Ruby program hadn't even begun reading or writing; the C++ program finished while the Ruby program was still initializing the Ruby runtime libraries.
Is C++ fast? Yes, it can be. But it's only fast if the developer understands how to make it fast.
Don't use C++ because it's "fast". Use C++ because you understand what its intended purpose is: to be close to the hardware.
- zymhan 8y agoMaybe you should've saved your breath and read the first paragraph to see that this is in fact about C++ vs C, not some other high level language.
- the_duke 8y agoMaybe you should have spent a bit more time thinking about the above comment. While using Ruby as an example, the point is not related to higher level languages. If you don't understand your tools, you can use them so inefficiently that other, supposedly worse tools are much faster.
- zymhan 8y agoThe last thing HN needs is discussions based around a comment from someone who didn't read the article. I don't care about your contextless philosophy.
- deleted 8y ago[deleted]
- grecy 8y agoI really like your comment, thanks. I suppose the question that many people would like to ask, but it's hard to test is: "Can we rank the speed of languages, given each are used by a domain expert to take full advantage of the features of that language" or some such. i.e. if a masterful C programmer and a masterful C++ programmer and a masterful Java Programmer and a masterful Ruby programmer all write something, which is faster. I'm sure the answer is "it depends", because that's always the answer.
- jungler 8y agoFor that particular question: They would all be the same speed because the optimization requirement would lead each one to write a compiler in their language of choice that emits a perfectly tuned assembly binary. What gets overlooked in language performance is that you pick a language for what are, in essence, placeholder constructs. The performance matters only in that you need it to be fast enough "off the shelf" that you don't have to start writing a compiler. But you generally aren't prevented from using that approach to boost your existing code, and high performance systems often converge on that strategy in some degree, because it lets you keep maintainable source code and add toggles for debugging and optimization that you won't get from treating the application and compiler code as separate entities.
- inetknght 8y agoAfter reading the article, I think my anecdote is still relevant, and that the article reinforces it. As @the_duke surmised: If you don't understand your tools, you can use them so inefficiently that other, supposedly worse tools are much faster. The article doesn't mention what versions of each compiler was used. I'd also challenge the author to use Compiler Explorer to discover compiled-to-assembly-level differences between their C and C++ code. https://gcc.godbolt.org/ https://gcc.godbolt.org/