Re:Is C++ fast?
by FreezerburnV on Friday January 18, 2019 @10:18AM
(#18939838)
I said this elsewhere, but I would legitimately like to see a program like what the author wrote, written in idiomatic C++ that performs as well as what the author got to. Maybe in a comparison style like the author to show the slower C++, the faster "C with classes", and the comparable speed "idiomatic C++" or something. I feel like I see people saying that idiomatic C++ is just as fast as something, while other people say that idiomatic C++ is slower and should be replaced. I'm going to assume you can for sure write C++ using the STL to be just as fast, and would like to learn what needs to be done to get to that point so I can incorporate those techniques into my own C++ code where I might need that extra bit of performance. (I'm playing around with writing games in C++, so performance is more of a concern than an IO-heavy web server. Or I'm considering learning QT for making apps, etc.)
[ Parent
| on HN ]
Re:Is C++ fast?
by mynegation on Friday January 18, 2019 @12:50PM
(#18941155)
Author posted C version of their code[1]. As a couple of examples of how you can go back to idiomatic C++ starting from here:
1. replace all pointers by passing references to templatized vectors. On a high level of optimization they will be compiled to the same pointer arithmetic as C, but will give you type-safety on the source level.
2. Replace structs with clasess with short inlined accessors. On a high level of optimization they will be compiled to the same memory offset access
3. _If_ there is any value in making domain-specific sort generic - make it such
[1] https://gist.github.com/zeux/bf847986e0474cf48f61bb5749da38e...