3 ms·
You don't have to be an expert to write Fast C++ that beats Java. I wrote a simple for loop and when compiled with -O3 it beat the Java version of it. You just
by v8dev123 5y ago
You don't have to be an expert to write Fast C++ that beats Java. I wrote a simple for loop and when compiled with -O3 it beat the Java version of it.
You just need to know your tools, that's it. Plenty people forget -O flag and existence of libraries like Folly.
If you combine PGO along with these must knows, you seriously will become much more faster.
- kaba0 5y agoA for loop is not too interesting application -- it is not what Java optimizes for, and chances are you didn't benchmark it correctly. To optimize your program in a low level language you have to basically have a whole plan for the architecture of your program beforehand, and every major change to that will break your optimizations. Also, don't forget about non-standard object life cycles, which is really common. Complex C++ programs basically employ their own GCs, which will be inferior to any one included in the JVM. Of course low-level programs have their place (plenty of), eg. audio processing, embedded, million other, but the average business/CRUD app will be faster* both to execute and to produce in Java, as well as better maintainable. * With enough time a competent team could of course write a faster version of it in C++, but it's not a good use of their time, and you would be surprised how hard it, especially with ever-changing requirements.
- v8dev123 5y agoC++ is not just a low level language. It's consists both high level and low level. C however a low level language. I bench-marked using Intel vTune. for loop is interesting. It's why Tensorflow Core written in C++ instead Java. I don't know any complex C++ program that employ their own GCs when C++ has RAII which is superior to GC. Just give a try for C++11/14/17 and you will see which one is more maintainable and expressive. Look at Chromium codebase. It's the most beautiful codebase I've ever been to. I've done a lot of CRUD web apps in C++ using expresscpp [1] and I would say it's easy as ABC. A lot of Java folks haven't tried C++11/14/17 (Modern C++). C++ is Zen of OOP. [1] https://github.com/expresscpp/expresscpp https://github.com/expresscpp/expresscpp
- kaba0 5y ago> C++ is not just a low level language A language either cares about low level details or not. You can’t have it both ways. And c++ is absolutely a low level language. > I don't know any complex C++ program that employ their own GCs when C++ has RAII which is superior to GC. RAII is not at all a replacement for GC. It is only suitable for a subset of object lifetimes. There are plenty of cases where you can’t really pinpoint a scope-exit where this given object should be reclaimed. A GC is a necessity in many concurrent algorithms that simply could not be written without. > Just give a try for C++11/14/17 I have and I like it. There are domains where I would not even start writing Java, and vice versa with C++. Your CRUD app may have been a breeze but what if the requirement has changed now touching on a core of your program. You have to refactor and it will be really expensive, compared to a high level language. Every memory allocation/deallocation have to be thought out again and tested (and while rust can warn about it, you still have to write a major refactor as it is another low level lang)
- v8dev123 5y ago> A language either cares about low level details or not. You can’t have it both ways. And c++ is absolutely a low level language. Please tell me why you can't. C++ is both not one. It's a multi paradigm language. In Modern C++, the low level details invisible. > Every memory allocation/deallocation have to be thought out again and tested True If you're writing C with Classes or Java Style C++. >> C with Classes >>> malloc() >> Java Style C++ >>> new and delete everywhere > There are plenty of cases where you can’t really pinpoint a scope-exit where this given object should be reclaimed. Show me. I'd bet your case can be solved with xvalues. > A GC is a necessity in many concurrent algorithms that simply could not be written without. Show me a concurrent algorithm that needs GC. > but what if the requirement has changed now touching on a core of your program. C++ is a OOP language just like Java. You do it same way as you do in Java. Use inheritance. > major refactor as it is another low level lang No. It's not a low level language if you write Modern C++. The case for Java very clear prior 2011 but now C++ has caught up.
- kaba0 5y ago