Thanks Christopher, this is a useful test case. I suspect the problem
here is our horribly inefficient implementation of
BufferedReader.readLine(). Given that it is calling a synchronized
read() method in a loop for every character in the stream, I'm
surprised its only 3x slower! You might like to have a go at making a
more efficient implementation, or alternatively, file an "RFE" bug in
bugzilla.
This has gone unclaimed for awhile, so I started messing around with
it.
Actually, the problem isn't with the read() method. Although the call
to it is synchronized, it gets called once and then the entire filled
contents of the buffer are used.
In the code below, I got rid of the synchronization, but the major gain
came from reusing the StringBuffer throughout the lifetime of the
BufferedReader
instance. This got me from 33s to 23s on my P450/256M. (The JRE time
is 15s.)
I'm able to get an additional 2s gain (10%) by implementing lineEnd()
in CNI,
thereby presumably avoiding the bounds checking.