first test

Bryce McKinlay mckinlay@redhat.com
Thu Jul 15 16:04:00 GMT 2004


Andrew Haley wrote:
>This isn't a test of the compiler, because it spends almost of of its
>time inside the library calls. It's really a test of the performance
>of the different Java runtime libraries.
>>However, I get 3860 ms for the JIT compiler and 4613 ms for gcj. That
>means that gcj's implementation of strings and/or memory allocation is
>slightly slower.
>>
Actually this test isn't really fair, because a JIT compiler can inline 
the String.valueOf() call and discover that the whole loop is a no-op. 
GCJ could eventually do this too if String.valueOf() doesn't cross a 
binary boundary. Typically, however, programmers don't write code that 
doesn't do anything, so this benchmark is not a valid test of real 
application performance.
Here's a better variant:
public class Loop {
 static final int N = 2500000;
 public static String[] sa = new String[N];
 public static void main(String[] args) {
 long before = System.currentTimeMillis();
 for (int i=0; i < N; i++){
 int a = 27 + 3 * i;
 sa[i] = String.valueOf(a) + "hello";
 }
 long after = System.currentTimeMillis();
 System.out.println("time: " + (after-before));
 }
}
For this case, I get 3203ms for "gcj -O2" and 5013ms for Sun Java 1.5 beta.
Regards
Bryce


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /