javac优化标志 [英] javac optimization flags

查看:117
本文介绍了javac优化标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在C写了很多代码,现在正在切换到Java。我目前正在实现一个大型数据结构,并想知道是否有任何优化标志我可以打开时,我调用Java编译器,以提高性能,如gcc。

I've recently been writing a lot of code in C and am now switching over to Java. I'm currently implementing a large data structure and was wondering whether there were any optimization flags I can turn on when I invoke the Java compiler in order to improve performance like in gcc.

我习惯于:

gcc -O3 -NDEBUG MyProgram.c

是否有类似的命令 javac

我使用JDK并运行Ubuntu 10.04。

I'm using JDK and am running Ubuntu 10.04.

推荐答案

Java中的优化主要由JIT编译器在运行时。因此,没有点尝试指示它在编译时优化某种方式(当它只创建字节码无论如何)。 JIT几乎肯定会在现场做出更好的决策,知道确切的环境和观察代码的特定部分的实际执行模式。

Optimization in Java is mostly done by the JIT compiler at runtime. Hence there is no point trying to instruct it to optimize a certain way at compile time (when it is creating only bytecode anyway). The JIT will almost surely make better decisions on the spot, knowing the exact environment and observing the actual patterns of execution of specific parts of your code.

有一些特定的编译器选项影响性能,但这些都是用于调优JVM(包括垃圾收集器),而不是优化代码本身。

There are some specific compiler options affecting performance, but these are for tuning the JVM (including the garbage collector) rather than optimizing the code itself.

这篇关于javac优化标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆