Re: Why is Java so slow????
Java Performance Expert wrote:
On my system, it takes 9.21 seconds (Java) and 1.1 seconds (C)
Any ideas?
It might have something to do with your locale or your system libraries.
Even though you are using a BufferedOutputStream writer, each call to
getBytes() on the string still runs an encoder.
The following is much faster than any of my previous tests on my system.
Give it a shot. It does not (yet) count, but it does spam IO so we
can at least see if it might yield some improvements.
static public void rawTest( String [] args ) throws IOException {
int lim = new Integer( args[0] );
String message = "This is line ";
String sed = "0000000\n";
OutputStream os = new BufferedOutputStream(System.out);
byte [] mbuff = message.getBytes();
byte [] sedBuff = sed.getBytes();
int mlength = mbuff.length;
int sedLength = sedBuff.length;
for( int i = 0; i < lim; i++ ) {
os.write( mbuff, 0, mlength );
os.write( sedBuff, 0, sedLength );
}
}
Note: not complete, just paste it in and have main() call it.