Re: Why is Java so slow????
On Nov 19, 3:37 pm, Mark Space <marksp...@sbc.global.net> wrote:
Java Performance Expert wrote:
Also, I saw comments this is "not a valid benchmark." Actually
this script is being used to pipe test input to a database processing
stream, and it was thought the component of the pipe that simply emits
the test data would be so negligible as to be ignored. However the
factor of ~ 70 slowdown w/ Java version is causing that to be an
issue.
Did you try not flushing the stream, as indicated above?
OK, that helped a lot. I can now generate 50m lines in 28 seconds,
which is only 2.5 X slower than in "C". We can probably live with
that.
I am wondering if I have "taken it to the limit" tho. Revised class
is below.
I still don't think I'm getting the benefits of native compilation.
Another poster remarked:
Your Java example flushes the output buffer on every line while the C
example does not. However even if you fixed that difference it is hard
to see what useful conclusion could be drawn from such a benchmark.
The useful conclusion that can be drawn is that a test generator
written in "C" will run faster, and so be more desirable to use, than
one written in Java, to the extent that it is desirable for each and
every component to run as fast as possible, and to the extent that it
is useful to identify those aspects of our decision making that
produce desirable results.
Let me know if anything is unclear..
Thx
Larry
import java.io.BufferedOutputStream;
import java.util.Date;
class t1
{
static public void main(String[] argv)
{
int lim = new Integer(argv[0]);
int nbench = new Integer(argv[1]);
int b;
for (b=0; b < nbench; b++) {
System.err.println("Bench " + b);
Date start = new Date();
try {
mytest(lim);
}
catch ( Exception e) {
}
Date now = new Date();
System.err.println("Took " + ((now.getTime() -
start.getTime())/1000) + " seconds");
}
}
static public void mytest(int lim) throws Exception
{
int i;
BufferedOutputStream bos = new
BufferedOutputStream(System.out, 1000000);
for (i=0; i < lim; i++) {
String s = "This is line " + i;
byte[] barr = s.getBytes();
bos.write(barr, 0, barr.length);
}
}
}