Java 性能提示 [英] Java performance tips

查看:52
本文介绍了Java 性能提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 C 移植到 Java 的程序.这两个应用程序都使用快速排序来排序一些分区数据(基因组坐标).

I have a program I ported from C to Java. Both apps use quicksort to order some partitioned data (genomic coordinates).

Java 版本运行速度很快,但我想让它更接近 C 版本.我使用的是 Sun JDK v6u14.

The Java version runs fast, but I'd like to get it closer to the C version. I am using the Sun JDK v6u14.

显然我无法与 C 应用程序匹敌,但我想了解我可以做些什么来尽可能(在环境限制范围内)尽可能提高性能.

Obviously I can't get parity with the C application, but I'd like to learn what I can do to eke out as much performance as reasonably possible (within the limits of the environment).

我可以做哪些事情来测试应用程序不同部分的性能、内存使用情况等?具体我该怎么做?

What sorts of things can I do to test performance of different parts of the application, memory usage, etc.? What would I do, specifically?

此外,我可以实施哪些技巧(通常)来更改类和变量的属性和组织,从而减少内存使用并提高速度?

Also, what tricks can I implement (in general) to change the properties and organization of my classes and variables, reducing memory usage and improving speed?

编辑:我使用的是 Eclipse,显然更喜欢任何第三方工具的免费选项.谢谢!

EDIT : I am using Eclipse and would obviously prefer free options for any third-party tools. Thanks!

推荐答案

不要试图超越 jvm.

do not try to outsmart the jvm.

特别是:

  • 不要试图避免创建对象为了性能

  • don't try to avoid object creation for the sake of performance

使用不可变对象适用.

使用对象的作用域正确,以便 GC 可以执行其工作.

use the scope of your objects correctly, so that the GC can do its job.

在你想要的地方使用原语原语(例如不可为空的 int与可为空的整数相比)

use primitives where you mean primitives (e.g. non-nullable int compared to nullable Integer)

使用内置算法和数据结构

use the built-in algorithms and data structures

处理并发时使用 java.util.concurrent 包.

when handing concurrency use java.util.concurrent package.

正确性高于性能.先做对,然后测量,然后用分析器测量,然后优化.

correctness over performance. first get it right, then measure, then measure with a profiler then optimize.

这篇关于Java 性能提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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