gcj's IO performance vs blackdown JDK
Christopher Marshall
christopherlmarshall@yahoo.com
Mon Dec 1 16:07:00 GMT 2003
All:
I have noticed that the blackdown JDK's file reading performance is roughly three
times as fast as libgcj's, when measured by simple line counting programs.
I ran my test with gcj 3.2.2.
I have written a lot of programs that process huge text files a line
at a time at my work that are 2 to three times slower running under gcj than running under
the JDK and I am pretty sure this I/O issue is the cause.
I would love to ditch the JDK in favor of gcj but can't because of this
performance issue.
I wrote a bash script and a pair of simple java programs to verify this which
I have included below. I have marked the beginning of each file with the
filename pre and post-fixed with "--". The files/marks are these
--run_benchmark--
--Hashgen.java--
--line_count.java--
run_benchmark is the bash script. line_count.java is the line counting program.
Hashgen.java generates the text file read by line_count.java.
run_benchmark uses Hashgen.java to generate a 100000 line text file with 1000
character lines. On my machine (433 Mhz celeron dell laptop running slackware
linux 9.0), it takes the JDK 11.1 seconds to run line_count against the file
and it takes the gcj compiled version 34.6 seconds.
The corresponding C line counting program, just for kicks, takes 1.2 seconds to run.
Chris Marshall
--run_banchmark--
#!/bin/bash
function compile_gcj {
local class=$1
gcj -c ${class}.java
gcj --main=${class} -o ${class} ${class}.o
}
compile_gcj Hashgen
compile_gcj line_count
javac line_count.java
data_file="data1.txt"
fill_char="a"
postfix="1"
line_length=1000
num_uniq_lines=200
num_lines=100000
echo "generating data file"
Hashgen $fill_char $postfix $line_length $num_uniq_lines $num_lines > $data_file
echo "running gcj version"
time line_count < $data_file
echo "running jdk version"
time java line_count < $data_file
--Hashgen.java--
import java.io.*;
public class Hashgen {
public static void main(String args[]) throws Exception {
String usage="Hashgen <fillchar> <0|1> <line length> <num uniq> <num lines>";
if (args.length<4){
System.err.println(usage);
System.exit(1);
}
char fill_char=args[0].charAt(0);
int post=Integer.parseInt(args[1]);
int line_length= Integer.parseInt(args[2]);
int num_unique=Integer.parseInt(args[3]);
int num_lines=Integer.parseInt(args[4]);
boolean postfix= (post==1);
int i=0;
// build pattern string
char ca[]= new char[line_length];
for (i=0; i<line_length; i++){
ca[i]= fill_char;
}
String pattern= new String(ca);
if (postfix){
for (i=0; i<num_lines; i++){
System.out.println(pattern+(i%num_unique));
}
}
else {
for (i=0; i<num_lines; i++){
System.out.println((i%num_unique)+pattern);
}
}
}
}
--line_count.java--
import java.io.*;
public class line_count {
public static void main(String args[]) throws Exception {
BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
String line= in.readLine();
int num_lines=0;
while (line!=null){
num_lines++;
line= in.readLine();
}
System.out.println(num_lines);
}
}
__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
More information about the Java
mailing list