why gcj is slower than jvm
guw
guw@koal.com
Wed Sep 3 06:05:00 GMT 2003
Hello!
I write a JAVA programme and compile it with GCJ. then I compare GCJ's performance with JVM'performance,but I discover that the procedure to be GCJ compiled is slower than JVM.
why?
thanks.
===============================================================================
Output data:
JVM:
SHA1: Hashing 100000 blocks of 500 bytes each: time = 5.276, speed = 9254.762 KB/s
MD5: Hashing 100000 blocks of 500 bytes each: time = 3.578, speed = 13646.765 KB/s
GCJ:
SHA1: Hashing 100000 blocks of 500 bytes each: time = 8.719, speed = 5600.1978 KB/s
MD5: Hashing 100000 blocks of 500 bytes each: time = 14.337, speed = 3405.7422 KB/s
===============================================================================
Compiled command:
gcj -O2 --main=HashSpeed HashSpeed.class -o HashSpeed.exe
===============================================================================
Source code:
import java.security.MessageDigest;
import java.util.Iterator;
public class HashSpeed {
public static void main(String[] args) {
if (args == null || args.length == 0) {
speed("SHA-1");
}
else{
int i=0;
while(i<args.length){
speed(args[i++]);
}
}
}
private static void speed(String name) {
try {
MessageDigest hash = MessageDigest.getInstance(name);
speed(hash);
} catch (Exception x) {
System.out.println(name+": Failed self-test...:"+x.getLocalizedMessage());
}
}
private static void speed(MessageDigest hash) {
try {
int iterations = 100000;
int blocksize = 500;
byte[] data = new byte[blocksize];
int i;
for (i = 0; i < blocksize; i++) {
data[i] = (byte) i;
}
System.out.print(hash.getAlgorithm()+": Hashing "+String.valueOf(iterations)
+" blocks of "+String.valueOf(blocksize)+" bytes each: ");
long elapsed = -System.currentTimeMillis();
for (i = 0; i < iterations; i++) {
hash.update(data, 0, blocksize);
}
elapsed += System.currentTimeMillis();
float secs = (elapsed > 1) ? (float) elapsed / 1000 : 1;
float speed = (float) iterations * blocksize / 1024 / secs;
System.out.println("time = "+secs+", speed = "+speed+" KB/s");
} catch (Exception x) {
x.printStackTrace(System.err);
}
}
}
archer
guw@koal.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rabbit.GIF
Type: image/gif
Size: 1488 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20030903/1e887dda/attachment.gif>
More information about the Gcc-help
mailing list