5 ms·
The very first comment misunderstands reality. It talks about how you can make java programs that outrun C++ ones using hotspot. Ignoring, of course, the fact t
by DannyBee 15y ago
The very first comment misunderstands reality.
It talks about how you can make java programs that outrun C++ ones using hotspot.
Ignoring, of course, the fact that nothing really stops you from making a good C++ JIT except engineering time, and it would do just as well in those cases.
Nobody does it because the cases in which it would help are small, and most of those folks are willing to do profiling/training runs, and get about as good results, even if it requires more pain.
As Herb said, the languages were made for different tradeoffs.
Speaking as a compiler guy, yes, you can make almost any of them as fast as each other given enough time and effort.
But putting time and effort into a JIT may not be as effective as choosing a different language.
- barrkel 15y agoIf you redefine C++ so that it looks like Java / C# (i.e. runs on a virtual machine, with a JIT and probably some requirements for memory safety), then yes, you can do these things with C++. But the people who advocate C++ wouldn't recognize that language as a C++, because all the overhead of a JIT runtime violates the "only pay for what you need" dictum. (E.g. consider the uptake of Managed C++, C++/CLI, etc.; which effectively are what you describe.)
- DannyBee 15y agoI think you may be confused. You don't have to redefine anything at a language level to make this work. It will just work. The features Java redefined were mainly for security reasons, and pointer safety, not because it made it possible to run with a JIT As a proof, you can JIT C/C++ with LLVM right now if you wanted to. It's not a great JIT because it has no adaptive compilation heuristics, etc, but it works just fine. C/C++ very specifically leave most of the execution environment undefined. They do not require anything that makes JIT'ing require language level changes. Your JIT may be unsafe (IE crash as easily as a regular C/C++ program), or otherwise require basically native access (IE not really viable for sandboxing in a browser), but it would work fine Things like Managed C++/etc required language changes because they wanted it to interoperate with a common intermediate language and runtime. There are things that you can do in C++ that you can't do in CLR (again, because the CLR chose safety/etc over other considerations), and vice versa (IE garbage collection at a language level), so managed C++ required language changes to support this.
- barrkel 15y agoI'm not confused (thank you very much for your diagnosis though - that's a grand way to gratuitously insult people). I didn't say redefining things at the language level; I meant redefining at the programming environment level. You can compile standard C++ with C++/CLI just fine, and have it run on a fine managed platform. "IJW" was the slogan: It Just Works. Still didn't go anywhere. (The CLR did not choose safety over other considerations. It has a safe subset, but it is not like the JVM; it has unsafe operations too. When you write IL for it, you are not even required to use GC memory; you can manipulate things at the level of untyped blobs of data if needs be.)
- wisty 15y ago> Speaking as a compiler guy, yes, you can make almost any of them as fast as each other given enough time and effort. But putting time and effort into a JIT may not be as effective as choosing a different language. So, the most "bang for your buck" may be using a JIT for a language like Python. Sure, it won't be as fast (at least, not until a huge amount of work has been done on it), but it can get faster. Trying to beat C + a good C compiler is ... ambitious.
- jules 15y agoBut possible: http://shootout.alioth.debian.org/u64q/fortran.php http://shootout.alioth.debian.org/u64q/fortran.php Doing it for Python will be impossibly hard, yes.
- wisty 15y agoYes, fortran is actually faster than C for some things. OK, C++ with the right templates, or a later C standard can theoretically do what Fortran does (remind me again - pass by reference, no recursion, and bounded arrays rather than pointers?). And Intel tends to be faster than gcc. There's no way you can make broad statements (like "nothing will beat C" or "fortran is actually faster than C for numerical stuff") without having a few exceptions. Actually, Pypy is faster than C, in extremely specific circumstances (i.e. ones which were set up by the Pypy people to show off, see "PyPy faster than C on a carefully crafted example" ... thought they point out there are things you could do in C to make it win). The most bang for you buck in JITs is for dynamic languages, because while stuff like type inference can exponentially explode, you'll only really have 1 type in many cases (i.e. a float), and the JIT can pick that up. And getting Python within an order of magnitude of C would be a massive win.