0

I have tried to test Java performance on OpenVMS (Itanium, OS 8.3). I created some sample classes to test performance as below

HEZ[AUN]$type Test.java

import java.util.Date;

public class Test {
    public static void main(String args[]) {
        Date d1 = new Date();
        System.out.println(d1);
        for (int k = 0;k < 1;k++) {
            for (int i = 0;i < Integer.MAX_VALUE;i++) {
                for (int j = 0;j < Integer.MAX_VALUE;j++) {

                }
            }
        }
        Date d2 = new Date();
        System.out.println(d2.getTime() - d1.getTime());
    }
}

HEZ[AUN]$type Test2.java

import java.util.Date;

public class Test2 {
    public static void main(String args[]) {
        Date d1 = new Date();
        System.out.println(d1);
        // for (int k = 0;k < 1;k++) {
        for (int i = 0;i < Integer.MAX_VALUE;i++) {
            for (int j = 0;j < Integer.MAX_VALUE;j++) {

            }
        }
        // } 
        Date d2 = new Date();
        System.out.println(d2.getTime() - d1.getTime());
    }
}

I then compiled as follows:

HEZ[AUN]$javac Test.java 
HEZ[AUN]$javac Test2.java 
HEZ[AUN]$java "Test"    
Tue Feb 21 18:04:57 GMT+07:00 2012 
3574 
HEZ[AUN]$java "Test2" 
Tue Feb 21 18:05:03 GMT+07:00 2012 
282

From the above, I don't understand why code that has an additional line for loop "for 1 time" is taking more time when compared with code "without for"

Should I modify some OpenVMS system parameter?

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67

1 Answers1

4

Java performance is complex and subtle.

Your test is not remotely sophisticated enough to tell you anything at all.

You should go buy and read the books "Java Performance" by Charlie Hunt and "Java Performance Tuning" by Jack Shirazi

There's so much that's wrong with your example that I don't think it's worth trying to fix it. A little knowledge in this area is a very dangerous thing.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67
kittylyst
  • 5,640
  • 2
  • 23
  • 36