I have a program I ported from C to Java. Both apps use quicksort to order some partitioned data (genomic coordinates).
The Java version runs fast, but I'd like to get it closer to the C version. I am using the Sun JDK v6u14.
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?
EDIT : I am using Eclipse and would obviously prefer free options for any third-party tools. Thanks!
This chapter provides information about how to improve performance for your Java applications in the Solaris 8 environment. An application's performance can be defined as its usage of resources; therefore, performance tuning is the minimizing of its usage of those resources.
Python and Java are two of the most popular and robust programming languages. Java is generally faster and more efficient than Python because it is a compiled language. As an interpreted language, Python has simpler, more concise syntax than Java.
do not try to outsmart the jvm.
in particular:
don't try to avoid object creation for the sake of performance
use immutable objects where applicable.
use the scope of your objects correctly, so that the GC can do its job.
use primitives where you mean primitives (e.g. non-nullable int compared to nullable Integer)
use the built-in algorithms and data structures
when handing concurrency use java.util.concurrent package.
correctness over performance. first get it right, then measure, then measure with a profiler then optimize.
Obviously, profile profile profile. For Eclipse there's TPTP. Here's an article on the TPTP plugin for Eclipse. Netbeans has its own profiler. jvisualvm is nice as a standalone tool. (The entire dev.java.net server seems to be down at the moment, but it is very much an active project.)
The first thing to do is use the library sorting routine, Collections.sort; this will require your data objects to be Comparable. This might be fast enough and will definitely provide a good baseline.
General tips:
StringBuilder
(not StringBuffer
because of that lock thing I just mentioned) instead of concatenating String
objectsfinal
; if possible, make your classes completely immutableArrayList
(or even an array) so the memory you're accessing is contiguous instead of potentially fragmented the way it might be with a LinkedList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With