Java Performance Tuning

Java(TM) - see bottom of page

|home |services |training |newsletter |tuning tips |tool reports |articles |resources |about us |site map |contact us |

Our valued sponsors who help make this site possible
New Relic: Try free w/ production profiling and get a free shirt! 

ManageEngine's Site24x7: End-to-End analysis on Java EE web transactions. Sign up for FREE! 

AppDynamics: Get complete browser to backend visibility. Monitor Now! 

Tool Report: J-Sprint

Chart Java Jitter with jHiccup
Monitor and identify pauses in your Java apps. Download now

Use jKool analytics as a service
Spot patterns in time-series data - real-time and free

JProfiler
Get rid of your performance problems and memory leaks!


Java Performance Training Courses
COURSES AVAILABLE NOW. We can provide training courses to handle all your Java performance needs

See Your Message Here
You could have your tool advertised here, to be seen by thousands of potential customers

Java Performance Tuning, 2nd ed
The classic and most comprehensive book on tuning Java

Java Performance Tuning Newsletter
Your source of Java performance news. Subscribe now!
Enter email:


New Relic
New Relic: Try free w/ production profiling and get a free shirt!

ManageEngine
ManageEngine's Site24x7: End-to-End analysis on Java EE web transactions. Sign up for FREE!

AppDynamics
AppDynamics: Get complete browser to backend visibility. Monitor Now!


Chart Java Jitter with jHiccup
Monitor and identify pauses in your Java apps. Download now

Why is my application so slow?
Learn 3 ways to detect Java Application Performance Trends

JProfiler
Get rid of your performance problems and memory leaks!


Published October 2002

NOTE: THIS TOOL APPEARS TO NO LONGER AVAILABLE - if you know otherwise please contact us.
The JavaPerformanceTuning.com Tool Reports are designed to help readers make informed choices about the tools they may wish to use. JavaPerformanceTuning.com provides these reports as a service to our readers; JavaPerformanceTuning.com is not responsible for the information provided by the tool author or vendor, nor do we necessarily endorse the products mentioned. JavaPerformanceTuning.com is not responsible for any additional resources provided from the article (such as downloadable files or other accessible material), even where we host such material.

What does J-Sprint do?

J-Sprint is a shareware Java profiler that analyzes the CPU consumption and memory consumption of Java applications and Java applets. J-Sprint runs on Microsoft Windows (98, NT, 2000 and XP) platforms, and supports any virtual machine that implements the 'JVMPI' interface.

The J-Sprint profiler analyzes Java applications and applets while they are running. It generates reports that help you to find out:

While J-Sprint is analyzing the Java application or applet, the user can suspend and resume the application or applet, collect profiling data, clear profiling data, and trigger the garbage collector.

Where to get J-Sprint

You can download a free evaluation version at http://www.j-sprint.com/download.html.

Installing J-Sprint

Just copy the 'j-sprint.exe' executable to your harddisk, and run it. J-Sprint will create a folder 'temporary_resources' at that location. This folder, and the files in it, are cleaned up when you exit the profiler.

Uninstalling J-Sprint

Just delete the 'j-sprint.exe' executable from your harddisk

Using J-Sprint: An Example

To illustrate the use of J-Sprint, we will profile a simple a Java application that alphabetically sorts all lines in a file (view source code). The application is functionally correct, it sorts the lines correctly.

The Initial Tests

We'll use a set of test files containing lines with random characters as input for the program. Our first step is to time the tests. (Timings reported are from tests run on a Pentium III - 750MHz, using the java 1.3.1 runtime running in client mode.)

Table 1: timings of the original program (before profiling)

Number of linesTime
1000 s
5001 s
30002 s
50006 s
1000030 s
200002 min 11 s
300005 min 00 s
400009 min 00 s
5000014 min 11 s

As you can see from table 1, the performance is ok for small files, but for large file (> 10000 lines) the application is unacceptably slow. Next, we will use the J-Sprint profiler to pinpoint the performance problems in our application.

Starting J-Sprint

First, we start up J-Sprint and open the launch dialog and fill in the location of the main class and the arguments (see figure 1).

Figure 1: the launch dialog - program tab

For this example, we will focus on method profiling. So we switch to the profiling tab (see figure 2), and there we specify that J-Sprint should analyze CPU consumption:

Figure 2: the launch dialog - profiling tab

Running The Profiler I: The Basic CPU Profiling Report

The input file we specified for this profiling run contains 10000 lines. We start collecting profile data by clicking the "Launch" button, and just let the profiler run until the test has finished. Note that running an application in the J-Sprint profiler is only slightly slower than running it without profiling. When the program has finished, the profiling data is automatically collated. One of the reports that are created from that data is the basic CPU profiling report (see figure 3)

Figure 3: Basic CPU Profiling Report

The base samples are the samples that are taken while the program was within the body of a method.
The cumulative samples are the samples that are taken while the program was within the body of a method, or within one of its 'child methods'.

Analyzing The Profile

From the profiling report, we can immediately see that the application spends almost three quarters of its time (74%) within the 'sort()' method. If we take a look at the implementation of that sort() method (view source code), we can see that it uses a 'bubble sort' algorithm. This algorithm has a time complexity of O(n*n), which is not efficient for sorting large amounts of data. Since the sort method is performed on a java.util.List, it is much more efficient (and simpler!) to use the standard Collections.sort() method within the java.util class. The Collections.sort() algorithm has a time complexity of O(n * log(n)), which is a lot better, certainly for large amounts of data.

Repeating the tests

So we adapt the application to use Collections.sort() (view adapted source code), then repeat the timing tests on this adapted class (see table 2):

Table 2: timings of the adapted program (faster implementation of the sort () method)

Number of linesTime
1000 s
5000 s
30001 s
50002 s
100005 s
200009 s
3000014 s
4000019 s
5000023 s

If you compare the timings from table 1 with the new timings in table 2, you can see that our change caused a dramatic increase in performance. We got rid of the O(n*n) time complexity, so the program is now also usable for large amounts of data.

Running The Profiler II: The Context Report

Now we will extend our example further still. Let's run the profiler again on the improved Java program. This time, we will take a look at the context report (see figure 4. Note that the red annotations in the screen shot were added afterwards):

Figure 4: Context Report

In the context report, we can see that the 'main' method spends its time in three 'child methods' (first red rectangle):

So, at this point it is the 'readFrom' method that is the bottleneck in the program. Looking at the details of that method, we can see that it spends its time in five 'child methods' (second red rectangle):

Looking at the implementation of the 'readFrom' method (view source code), we can see that this implementation reads one character at a time from the file, and appends them to a StringBuffer until the end of a line is read. We can improve the speed of this method by buffering the I/O using the java.io.BufferedReader class. This class provides a method that reads one line of text from a file, using a buffering mechanism (view source code).

Repeating the tests again

After making those changes to the source file, we run our timings again, with the final spectacular result (see table 3):

Table 3: timings of the final program (faster implementation of the readFrom () method)

Number of linesTime
1000 s
5000 s
30000 s
50000 s
100001 s
200002 s
300002 s
400003 s
500004 s

Example Conclusion

J-Sprint has pinpointed two performance bottlenecks in the example Java program. After improving those problematic areas, the performance of the program is dramatically improved.

Other features of J-Sprint

The previous example showed how J-Sprint analyzes CPU consumption. J-Sprint can also analyze memory consumption. Other memory profile reports are then produced.

The Memory Profiling Report

Memory profiling reports show which methods consume a lot of memory. For an example see figure 5.

Figure 5: Memory Report

Memory monitor chart

J-Sprint also provides a memory monitor, a chart that continuously displays the amount of memory allocated, together with the amount of 'live' memory (memory that is not yet garbage collected). See figure 6. This is useful to get a general idea of memory allocation and garbage collection in your Java program.

Figure 6: The Memory Monitor

Printing and exporting reports

All J-Sprint reports can be printed or exported to HTML (only in the registered version). The look of the reports can be changed, and you can specify the sort order and filters on all reports (e.g. hide methods from certain classes or packages).

More info about J-Sprint.

J-Sprint aims to provide a cheap but fully featured Java profiler. J-Sprint is shareware: you are allowed to use it for free for evaluation purposes only. If you keep using it after evaluating it, you have to register your copy, and pay a license fee.

For more information: http://www.j-sprint.com/register.html.


Last Updated: 2014-10-29
Copyright © 2000-2014 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/tools/jsprint/index.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us