first test

Chris Burdess dog@bluezoo.org
Thu Jul 15 11:43:00 GMT 2004


Andrew Haley wrote:
>  > public class Loop {
>  > 
>  >      public static void main(String[] args) {
>  >          long before = System.currentTimeMillis();
>  >          for (int i=0; i < 1000000; i++){
>  >              int a = 27 + 3 * i;
>  >              String b = String.valueOf(a) + "hello";
>  >          }
>  >          long after = System.currentTimeMillis();
>  >          System.out.println("time: " + (after-before));
>  >      }
>  > 
>  > }
>  > 
>  > running it on Mac OS X 10.3.4 1.33 GHz G4:
>  > 
>  > java Loop
>  > time: 2269
>  > 
>  > gcj --main=Loop -o Loop Loop.java
>  > ./Loop
>  > time: 4369
>  > 
>  > ??? the app compiled with gcj is twice as much slow as the one running 
>  > through the VM ???
>  > Redoing the test doesn't change much.
> 
> 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.
> 
> I don't know why there is such a disparity in your case.  It is
> possible that on Mac OS X you have a fast implementation of Strings.

FWIW here are some more Mac OS X results (darwin kernel 7.4.0, 1GHz G4,
gcj 3.5.0 20040709):

time java Loop
time: 2066

real    0m2.803s
user    0m2.270s
sys     0m0.220s

gcj --main=Loop -o Loop Loop.java
time ./Loop
time: 3466

real    0m4.340s
user    0m3.920s
sys     0m0.100s

gcj --main=Loop -o Loop -O2 Loop.java
time ./Loop
time: 3372

real    0m4.230s
user    0m3.900s
sys     0m0.050s
-- 
Chris Burdess



More information about the Java mailing list