GCJ slower than JDK?

Bryce McKinlay bryce@waitaki.otago.ac.nz
Mon Jan 28 20:27:00 GMT 2002


Fernando Lozano wrote:
>>> Testing on a directory with about 3.000 jpg files and getting about 
>>> 76 duplicates, I found the program is three times slower when 
>>> compiled with gcj -O2 than when compiled and executed bu a Java SDK. 
>>>>>> If you'd like to post your small test program, we can take a look at 
>> it and see why it might be slower. 
>>> Thanks a lot. Its attached to this message. Please forgiveme my 
> variable names, I am not a native english speaker. :-) 

I tried it out. Without any changes, GCJ came out just slightly ahead of 
JDK 1.4beta2 w/ Hotspot client VM:
$ gcj -O2 DupFinder.java --main=DupFinder
$ /usr/bin/time ./a.out /usr/lib/* > /dev/null
58.32user 1.91system 1:00.27elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (1326major+623minor)pagefaults 0swaps
$ /usr/bin/time java DupFinder /usr/lib/* > /dev/null
62.04user 1.86system 1:04.17elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
But really the problem is with your code. By giving the Adler32 a buffer 
to workwith instead of calling it one byte at a time, it will run much 
faster:
--- DupFinder.java.old Tue Jan 29 16:17:27 2002
+++ DupFinder.java Tue Jan 29 16:14:09 2002
@@ -100,6 +100,8 @@
 return newDups;
 }
 
+ static byte[] buffer = new byte[1024];
+
 static private long getChecksum (File f) throws IOException
 {
 //java.util.zip.CRC32
@@ -108,7 +110,8 @@
 CheckedInputStream in = new CheckedInputStream (
 new BufferedInputStream (new FileInputStream (f)),
 checksum);
- while (in.read () != -1) ;
+ while (in.read (buffer, 0, 1024) != -1) ;
+
 return checksum.getValue ();
 }
Now I get:
$ /usr/bin/time ./dupf /usr/lib/* > /dev/null
2.11user 0.43system 0:02.54elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (1326major+624minor)pagefaults 0swaps
with GCJ, and:
$ /usr/bin/time java DupFinder /usr/lib/* > /dev/null
4.46user 0.53system 0:05.20elapsed 95%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (1598major+925minor)pagefaults 0swaps
With HotSpot client. I'd also reccomend using ArrayList instead of 
Vector (its faster due to no synchronization), and likewise HashMap 
instead of Hashtable.
> I've heard horror stories about upgrading the gcc, glibc or related 
> components from Red Hat. May I get just gcj sources and use them 
> without fear or should I look for newer rpms from redhat? 

Its quite safe to build GCC from source and install it to a different 
place (configure --prefix=/my/path ...) thus not overwriting the default 
compiler.
regards
Bryce.


More information about the Java mailing list

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