Oh dear god, not this again.
Performance - The way C works is very close to the way that actual hardware typically works. This makes it efficient. It is also a compiled language which executes natively, whereas Java and many others run inside a virtual machine or are interpreted.
Oh dear god, not this again.
What is it about C/C++ that has left it the dominant language for the past umpteen years?
Performance - The way C works is very close to the way that actual hardware typically works. This makes it efficient. It is also a compiled language which executes natively, whereas Java and many others run inside a virtual machine or are interpreted.
Java compiles at runtime. Because of this it can actually run faster than C/C++ code since it converts the binary at runtime into native code. Java is interpreted once. After the first pass through any class it can actually run faster than C/C++.
Oh dear god, not this again.
Ummm ya ..... I'll stop now.
Java compiles at runtime. Because of this it can actually run faster than C/C++ code since it converts the binary at runtime into native code. Java is interpreted once. After the first pass through any class it can actually run faster than C/C++.
Ummm ya ..... I'll stop now.
Er, I he asked why C/C++ rule the compiled languages. At least, that's what the thread title says. C++ vs Java, entertaining as it always is, isn't really what he's asking if I understand right.
Actually, he did, so that makes my comment irrelevant as well.
I would argue that one of the reasons it hasn't been replaced is that it's good enough. There hasn't been a need to replace it. It's very well known. It's standardized. It's flexible enough to adapt to nearly any platform. Perhaps most importantly, the overall demand for compiled code is probably going down, so there wouldn't be tons of pressure to create a new language.
Please explain how doing the compilation during runtime will improve the speed over having the code already precompiled.
both Java and .Net runtimes compile "just in time", and the size of the overall program is irrelevant. It only compiles methods as needed, and only the first time each is called.The cost of a compiler is not cheap. For a small program it may be insignificant, but a large program can not stand the hit.
They can target x64, x86, or ARM, or even AMD vs Intel optimizations on the fly that wouldn't be available to a more generic codebase. They can also make decisions based on how much memory is available, how many cores, etc.Compilers are supposed to convert the source code into native binary targeted for the processor. so what is the miracle that Java is doing vs any other compiler package?
I've seen benchmarks done that show Intermediate langs like MSIL and Java Byte code do indeed outperform native code because CPU's have outpaced bandwidth so fast that it can load something small, compile, and run faster than native code can load something large, and run. Granted, these can be special cases, but it's been proven. And the further the push into multi-theading/multi-cored architectures, the more likely intermediade code will be to outperform native code.
both Java and .Net runtimes compile "just in time", and the size of the overall program is irrelevant. It only compiles methods as needed, and only the first time each is called.
They can target x64, x86, or ARM, or even AMD vs Intel optimizations on the fly that wouldn't be available to a more generic codebase. They can also make decisions based on how much memory is available, how many cores, etc.
The java client VM precompiles "hot spots" (parts of the program that will run a lot, such as loops) into native machine code when the program is launched. The rest of the program runs through a translative virtual machine, meaning every statement is compiled to native as it runs.
The java server VM precompiles the entire program into native code when it is launched, but even then, it is generally somewhat slower than C++.
There are some rare cases where Java has been shown to be faster than C++. This is because the Java VM can do some optimizations at runtime that wouldn't generally be done on a generic C++ executable but could be done if the programmer really wanted to. These are very specific cases though and in the real world Java is always going to be slower than a well coded C++ app.
Debian has an interesting site that does a speed comparison of all the major programming languages running on Debian. They do various CPU intensive benchmarks keeping the source code as close to the same as possible. C#/.NET is at an obvious disadvantage here since it's running on Mono.
http://shootout.alioth.debian.org/u32/which-programming-languages-are-fastest.php
And why would that make those measured program times misleading?Some of those results are misleading. Like this:
http://shootout.alioth.debian.org/u64q/performance.php?test=spectralnorm
First, no one uses the power method to compute eigenvalues; it's incredibly unstable & ill-conditioned.
N=5,500Second, the matrix size is very relevant here and it isn't stated.
So you think those results are misleading because they don't tell you about all the other programs that weren't measured - they only tell you about the programs that were measured?Third, the core of the power method is a matrix-vector multiply, A*x. Optimized BLAS libraries (GOTO2, MKL) exist that will beat like all of the implementations I looked at in that site for problem sizes >15-20 or so.
Until someone contributes that super C program with "the right compiler options" ...Fourth, there shouldn't be much of a difference between fortran and C here if you use the restrict keyword (in C) and pass the right compiler options.
No, not "like at least 4-5x"And it's worth noting that Java's memory usage is like at least 4-5x that of C in all the tests, if not more like 10x greater.
Momentum. A competitor would have to offer significant advantages to convince enough people to switch over. There are thousands of libraries out there for C and C++. Most of your middleware (3d engines, game engines etc) is written in one of the two, not to mention basically all of your APIs for interacting with the major operating systems.
http://www.python.org/doc/essays/omg-darpa-mcc-position.htmlProgram development using Python is 5-10 times faster than using C/C++, and 3-5 times faster than using Java.