28 ms·
If you are doing a lot of processing on numeric arrays, then no, Java is certainly not one of the faster languages. Its very difficult to have safety (for examp
by srean 14y ago
If you are doing a lot of processing on numeric arrays, then no, Java is certainly not one of the faster languages. Its very difficult to have safety (for example no out of bounds dereferencing of arrays) and performance. (An extremely interesting language that tries to do that is ATS http://en.wikipedia.org/wiki/ATS_%28programming_language%29 http://en.wikipedia.org/wiki/ATS_%28programming_language%29)
Yes in theory Java will elliminate most of those checks, but difference between theory and practice is more than what theory would suggest.
For simple loops for (i==; i < n; ++i) where n is a compile time constant (or something that can be proved to be a constant) this would work. But one encounters a lot of loops where n isnt a constant. This is just one example of what slows Java down, there are others. It overspecifies semantics (think order of evaluation of arguments), gaining safety but losing on performance.
That said I think the JVM is one of the best optimized runtime that we have. Overall JVM is a great platform, but Java is not necessarily the best way to exploit it. Coming back to Java performance, in my experience it would get to around 80% of the speed of a C or C++ code but would use 3~4 times the memory. No careful benchmarking this, just anecdotal experience.
JVM developers, in case you are reading this, please add tail call ellimination and SIMD.
I am not a "3 cheers for dynamically typed languages" person, but for Java I am willing to concede that the type system comes with the drawbacks but little benefit. In C++, and D you can pull the gloves off when required. And please dont get me started on JINI.
A problem is that Java based systems are slow both in the big (I am looking at you Hadoop) and the small. You can run some of the C++ based mapreduce implementations (http://sector.sourceforge.net/ http://sector.sourceforge.net/) and draw your own conclusion.
- camo 14y ago> I am not a "3 cheers for dynamically typed languages" person, but for Java I am willing to concede that the type system comes with the drawbacks but little benefit. In C++, and D you can pull the gloves off when required. And please dont get me started on JINI. I expect you mean JNI and not Apache JINI... That probably highlights the difference between Java and other languages you like to mention, it may use more memory and be marginally slower computationally, but when you take that the most interesting applications these days are distributed the ability to sort an array and save a few clock cycles fades into insignificance compared to network latency and connection times. Not to mention also, you can optimize your CPU's workload or you can optimize your personal workload. Java lets you pick great libraries off the shelf. Or you can choose to manually do your own array bounds checking and pick up your own garbage.