• <bdo id='Dr7dA'></bdo><ul id='Dr7dA'></ul>

      <small id='Dr7dA'></small><noframes id='Dr7dA'>

      <legend id='Dr7dA'><style id='Dr7dA'><dir id='Dr7dA'><q id='Dr7dA'></q></dir></style></legend>

    1. <i id='Dr7dA'><tr id='Dr7dA'><dt id='Dr7dA'><q id='Dr7dA'><span id='Dr7dA'><b id='Dr7dA'><form id='Dr7dA'><ins id='Dr7dA'></ins><ul id='Dr7dA'></ul><sub id='Dr7dA'></sub></form><legend id='Dr7dA'></legend><bdo id='Dr7dA'><pre id='Dr7dA'><center id='Dr7dA'></center></pre></bdo></b><th id='Dr7dA'></th></span></q></dt></tr></i><div id='Dr7dA'><tfoot id='Dr7dA'></tfoot><dl id='Dr7dA'><fieldset id='Dr7dA'></fieldset></dl></div>
        <tfoot id='Dr7dA'></tfoot>

        java什么时候比c++快(或者JIT什么时候比预编译快)?

        when is java faster than c++ (or when is JIT faster then precompiled)?(java什么时候比c++快(或者JIT什么时候比预编译快)?)

            <i id='TcsRf'><tr id='TcsRf'><dt id='TcsRf'><q id='TcsRf'><span id='TcsRf'><b id='TcsRf'><form id='TcsRf'><ins id='TcsRf'></ins><ul id='TcsRf'></ul><sub id='TcsRf'></sub></form><legend id='TcsRf'></legend><bdo id='TcsRf'><pre id='TcsRf'><center id='TcsRf'></center></pre></bdo></b><th id='TcsRf'></th></span></q></dt></tr></i><div id='TcsRf'><tfoot id='TcsRf'></tfoot><dl id='TcsRf'><fieldset id='TcsRf'></fieldset></dl></div>

            <small id='TcsRf'></small><noframes id='TcsRf'>

                • <bdo id='TcsRf'></bdo><ul id='TcsRf'></ul>
                  <tfoot id='TcsRf'></tfoot>
                  <legend id='TcsRf'><style id='TcsRf'><dir id='TcsRf'><q id='TcsRf'></q></dir></style></legend>
                    <tbody id='TcsRf'></tbody>
                  本文介绍了java什么时候比c++快(或者JIT什么时候比预编译快)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能重复:
                  JIT 编译器与离线编译器

                  我听说在某些情况下,由于 JIT 优化,Java 程序或更确切地说是部分 Java 程序能够比 C++ 中的相同"代码(或其他预编译代码)更快地执行.这是因为编译器能够确定一些变量的范围,避免一些条件并在运行时提取类似的技巧.

                  I have heard that under certain circumstances, Java programs or rather parts of java programs are able to be executed faster than the "same" code in C++ (or other precompiled code) due to JIT optimizations. This is due to the compiler being able to determine the scope of some variables, avoid some conditionals and pull similar tricks at runtime.

                  你能否举一个(或更好的——一些)例子,这适用于什么地方?并且也许概述了编译器能够优化字节码超出预编译代码可能的确切条件?

                  Could you give an (or better - some) example, where this applies? And maybe outline the exact conditions under which the compiler is able to optimize the bytecode beyond what is possible with precompiled code?

                  注意:这个问题不是关于比较 Java 和 C++.它关于 JIT 编译的可能性.请不要着火.我也不知道有任何重复.如果有请指出来.

                  NOTE : This question is not about comparing Java to C++. Its about the possibilities of JIT compiling. Please no flaming. I am also not aware of any duplicates. Please point them out if you are.

                  推荐答案

                  在实践中,您可能会发现在这些情况下,您编写的幼稚 Java 代码胜过幼稚编写的 C++ 代码(所有这些我都亲自观察过):

                  In practice, you're likely to find your naively written Java code outperform your naively written C++ code in these situations (all of which I've personally observed):

                  • 大量的小内存分配/释放.主要的 JVM 都有非常高效的内存子系统,垃圾收集比要求显式释放更有效(如果它真的想的话,它可以移动内存地址等).

                  • Lots of little memory allocations/deallocations. The major JVMs have extremely efficient memory subsystems, and garbage collection can be more efficient than requiring explicit freeing (plus it can shift memory addresses and such if it really wants to).

                  通过方法调用的深层层次结构进行高效访问.JVM 非常擅长删除任何不必要的东西,根据我的经验,通常比大多数 C++ 编译器(包括 gcc 和 icc)要好.部分原因是它可以在运行时进行动态分析(即,它可以过度优化,只有在检测到问题时才去优化).

                  Efficient access through deep hierarchies of method calls. The JVM is very good at eliding anything that is not necessary, usually better in my experience than most C++ compilers (including gcc and icc). In part this is because it can do dynamic analysis at runtime (i.e. it can overoptimize and only deoptimize if it detects a problem).

                  将功能封装到短暂的小对象中.

                  Encapsulation of functionality into small short-lived objects.

                  在每种情况下,如果您付出努力,C++ 可以做得更好(在空闲列表和块分配/解除分配的内存之间,C++ 几乎在所有特定情况下都可以击败 JVM 内存系统;通过额外的代码、模板和聪明的宏,您可以非常有效地折叠调用堆栈;并且您可以在 C++ 中拥有小型的部分初始化堆栈分配的对象,其性能优于 JVM 的短期对象模型).但你可能不想付出努力.

                  In each case, if you put the effort in, C++ can do better (between free lists and block-allocated/deallocated memory, C++ can beat the JVM memory system in almost every specific case; with extra code, templates, and clever macros, you can collapse call stacks very effectively; and you can have small partially-initialized stack-allocated objects in C++ that outperform the JVM's short-lived object model). But you probably don't want to put the effort in.

                  这篇关于java什么时候比c++快(或者JIT什么时候比预编译快)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)
                • <legend id='b5stK'><style id='b5stK'><dir id='b5stK'><q id='b5stK'></q></dir></style></legend>

                  • <tfoot id='b5stK'></tfoot>
                    • <small id='b5stK'></small><noframes id='b5stK'>

                    • <i id='b5stK'><tr id='b5stK'><dt id='b5stK'><q id='b5stK'><span id='b5stK'><b id='b5stK'><form id='b5stK'><ins id='b5stK'></ins><ul id='b5stK'></ul><sub id='b5stK'></sub></form><legend id='b5stK'></legend><bdo id='b5stK'><pre id='b5stK'><center id='b5stK'></center></pre></bdo></b><th id='b5stK'></th></span></q></dt></tr></i><div id='b5stK'><tfoot id='b5stK'></tfoot><dl id='b5stK'><fieldset id='b5stK'></fieldset></dl></div>
                          <tbody id='b5stK'></tbody>
                          <bdo id='b5stK'></bdo><ul id='b5stK'></ul>