Java Runtime Performance Vs Native C / C++ Code?

前端 未结 9 2282
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 14:10

I\'ve become more and more comfortable programming in Java than with C++ or C. I am hoping to get a sense of the performance hit incurred using a JVM interpreter, as oppose

相关标签:
9条回答
  • 2020-12-12 14:29

    Actually, a VM can do a lot of optimizations at runtime, based on information that's only available at runtime, that a C/C++ compiler cannot do. So, in most circumstances, the JVM will be at least as fast as a native program.

    Brian Goetz answers most, if not all of your questions in his talk Towards a universal VM.

    0 讨论(0)
  • 2020-12-12 14:32

    Important thing to note down is

    Java byte code JIT compiled to much more optimized code specific to particular hardware

    vs

    C code compiled and optimized to general hardware so it cannot take advantage of features provided by specific hardware

    0 讨论(0)
  • 2020-12-12 14:34

    Both java and c# (and objective-c) are not nearly as fast as native code can be. But that only matters if you have a problem where you are not engineering-time limited. Because you'll have the time to devise a better algorithm with a high level language.

    So basically, if you're developing a device where you're going to build a million a year of, or that is battery powered, you don't use java or c# to build its core functionality. You might add a lisp interpreter to make customisation easy, though. Microsoft is not going to use c# for say the core of SQL server, where performance really matters. Visual Studio on the other hand, where MS can expect users to have high-end hardware, can be used as a showcase for slow but high productivity technology.

    Please note that I currently do most of my programming in Pharo Smalltalk, which is a lot slower than java, c# or objective-c, and is not even one of the fastest Smalltalks. Productivity trumps performance.

    0 讨论(0)
提交回复
热议问题