This is a function I have to create timestamp string in %.7f format. This function takes only 2-3 ms to execute. But its called from many places in my code, by even optimizing it by 1 ms I will save 1 second in one particular user action. Any ideas?
public static String makeTimestamp()
{
long millis = System.currentTimeMillis();
String result;
Double ts = new Double((millis) / 1000.0);
ByteArrayOutputStream b = new ByteArrayOutputStream();
PrintStream p = new PrintStream(b);
p.printf("%.7f", ts );
result = b.toString();
try
{
p.close();
b.close();
} catch (IOException ioe) {};
return result;
}
If you absolutely need it, this is roughly 10 times faster than string formatting: