3 ms·
This is an old discussion, but I actually have this thread bookmarked so I can show young programmers the dangers of assuming that if you write in C++ it will b
by dkhenry 13y ago
This is an old discussion, but I actually have this thread bookmarked so I can show young programmers the dangers of assuming that if you write in C++ it will be faster then everything else out there.
- Negitivefrags 13y agoSeems like an odd conclusion to reach given that the end result was C++ being faster. Nobody ever claimed that C++ didn't require more knowledge to use effectively.
- dkhenry 13y agoActually C was the fastest, by a fairly wide margin, however hat doesn't matter much since you can make the C++ faster and you can make C go just as slow as the input buffered C. There are still lots of people who think that speed is solely a function of programing language with very little impact from program design. Like I said I like to bring this out when showing newer developers that no matter what language you pick you need to be aware of what is going on in the background and most importantly you should test you code before trying to assume what parts are fast and what parts are slow.
- nly 13y agoYes indeed, and many don't realize that C streams are also buffered and can also be tuned: http://www.gnu.org/software/libc/manual/html_node/Buffering-Concepts.html http://www.gnu.org/software/libc/manual/html_node/Buffering-... http://www.gnu.org/software/libc/manual/html_node/Controlling-Buffering.html http://www.gnu.org/software/libc/manual/html_node/Controllin... there are also threading issues: http://www.gnu.org/software/libc/manual/html_node/Streams-and-Threads.html http://www.gnu.org/software/libc/manual/html_node/Streams-an... glibc even lets you implement custom streams (FILE* handles that will work with fgets etc. but call your own source and sink to do i/o)
- lelandbatey 13y agoYes, but it's generally expected that if you do things the "usual way" in both Python and in C++, the C++ will always be faster.
- eliasmacpherson 13y agoMaybe the sensible takeaway is that if you can do a prototype in a simpler language first to establish a baseline, you should. I think most people expect that they can, due to their own ignorance, make a slow program even in C++.
- brandonbloom 13y agoYou're right, it is an odd conclusion, but lots of folks think that way. That's why Negitivefrags needs to dissuade inexperienced folks of that notion.
- dagw 13y agoI (re)learned the same lesson last year when I started looking at OpenCL. I saw all these awesome benchmarks about it was 40-50 times faster than C. I then did a bunch of simple tutorials and tests and got great performance. Then I rewrote a piece of performance critical C code I had and after a couple of days of hard work I had something that ran 5 times slower than my original C code.