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

前端 未结 9 2297
隐瞒了意图╮
隐瞒了意图╮ 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:21

    To address each of your points:

    • The overhead of interpreting code is much higher than 10-15% (I'd guess at along 3x-5x or higher). In order to get down to 10-15% you have to use some form of machine-code compilation step (i.e. JIT). (Try running a JVM with JIT switched off, and you'll see the performance drop like a rock.)
    • Garbage collection does have a performance impact, but I'd say that everyone agrees that it is worth it. If you can afford the byte-code compilation/interpretation overhead, you can afford the gc overhead as well.
    • Socket programming is much easier in Java than in C/C++, if that's what you're asking. And performancewise, the socket I/O overhead dominates over the Java execution overhead.
    • Most modern JVMs have true threads, i.e. each Java thread is executed by a kernel thread, allowing Java threads to utilize modern multi-core CPUs.

提交回复
热议问题