Name: skT45625 Date: 05/25/2000
java version "1.2.2"
Classic VM (build JDK-1.2.2-001, native threads, symcjit)
In running JProbe on our app, I noticed that one of the bottlenecks
was in the java.sql.Timestamp.toString() method. I tried the following
optimization and got a 25% improvement.
This call consumed 15% of the process time for a table population in our
application. So this optimization would be helpful to us.
I rebuilt rt.jar with the change to verify the improvement but that is not
a long term solution.
Thanks.
public String toString () {
int year = super.getYear() + 1900;
int month = super.getMonth() + 1;
int day = super.getDate();
int hour = super.getHours();
int minute = super.getMinutes();
int second = super.getSeconds();
// mod from here end
char buf[] = "2000-00-00 00:00:00.000000000".toCharArray();
buf[0] = Character.forDigit(year/1000,10);
buf[1] = Character.forDigit((year/100)%10,10);
buf[2] = Character.forDigit((year/10)%10,10);
buf[3] = Character.forDigit(year%10,10);
buf[5] = Character.forDigit(month/10,10);
buf[6] = Character.forDigit(month%10,10);
buf[8] = Character.forDigit(day/10,10);
buf[9] = Character.forDigit(day%10,10);
buf[11] = Character.forDigit(hour/10,10);
buf[12] = Character.forDigit(hour%10,10);
buf[14] = Character.forDigit(minute/10,10);
buf[15] = Character.forDigit(minute%10,10);
buf[17] = Character.forDigit(second/10,10);
buf[18] = Character.forDigit(second%10,10);
int value = nanos;
for (int pos = 28; value > 0 && pos > 19; pos--)
{
buf[pos] = Character.forDigit(value%10,10);
value /= 10;
}
return buf.toString();
}
Stats=======
Original New
#of calls 8442 8485
Cumulative Time 18966 14396
Method time 18966 14396
Cum Objects 364389 177289
Method Objects 364389 177289
filename Timestamp.java
msecs/call 2.246624 1.696641
(Review ID: 105335)
======================================================================