J
Jack Marsh
try this instead version of mytest, it wont be as fast as C but itJava said:=========================================================================
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();
mytest(lim);
Date now = new Date();
System.err.println("Took " + ((now.getTime() -
start.getTime())/1000) + " seconds");
}
}
static public void mytest(int lim)
{
int i;
for (i=0; i < lim; i++)
System.out.println("This is line " + i);
}
}
should be much faster than your code. On my XP computer it was a little
over 10x faster than your version. I used StringBuffer rather than
StringBuilder because StringBuffer has a length() method.
static public void mytest(int lim)
{
final int bufferSize = 100000;
StringBuffer b = new StringBuffer(bufferSize+100);
for (int i=0; i < lim; i++)
{
b.append("This is line " + i +"\n");
if ( b.length() >bufferSize) {
System.out.print(b.toString());
b = new StringBuffer(bufferSize+100);
}
}
// tidy up
if ( b.length() > 0) {
System.out.print(b.toString());
}
}