Quick Java Optimization Question

后端 未结 3 433
南旧
南旧 2021-01-05 00:00

Will the Eclipse compiler automatically convert multiplication by a power of two into a bit shift, or should I do that manually? Thanks for the help.

3条回答
  •  隐瞒了意图╮
    2021-01-05 00:41

    In general you cannot outsmart the JVM unless there is something very high level you know that cannot be deduced automatically. This usually means a better algorithm is available than the one which is currently used instead of having to handtweak your source. You can use the jvisualvm profiler available in the latest Java 6 JDK's to investigate your program and see where the bottlenecks are.

    For instance, the expense of creating new objects instead of reusing old ones has diminished radically then last 10 years, so you should not take any old advice for tuning your java program without examining if it still holds.

    You will, however, find that keeping your program simple and above all - readable - will make it much easier to maintain both for you and for future programmers. Any unneccessary complexity will baffle your future readers, and you will need to say in a comment why it MUST be like that (otherwise they will just refactor it back into its original form :)

提交回复
热议问题