[slf4j-user] Formatted logs and benchmarks
Sebastien Pennec
sebastien at qos.ch
Tue Jan 23 11:10:34 CET 2007
Hello Martin,
As a follow-up to our performance discussion, here are a few new figures that put the
differences between MessageFormatter and String.format() in perspective with a
typical log to a file.
We are logging to a file on the local host, with a simple PatternLayout.
With 1 parameter:
MessageFormatter 11 microseconds
String.format 24 microseconds
With 3 parameters:
MessageFormatter 13 microseconds
String.format 30 microseconds
With 0 parameters:
MessageFormatter 9 microseconds
String.format 11 microseconds
I've simply replaced the code inside MessageFormatter's arrayFormat method with a
call to String.format(), so that there is no difference in the calls sequence.
We can see that the difference stays important. Seeing these values, I think that we
should not use the String.format method instead of the MessageFormatter class. This
question was raised in the previous discussions about this subject, and these tests
give a clear view of the best choice, I think.
In one of your previous messages, you mentionned the StopWatch that you used to
measure the values. Based on this class' javadoc[1], it calls the
System.currentTimeMillis() method to measure time. The System.nanoTime() method is
much more precise and constant than System.currentTimeMillis(). You might expect more
constant result using it rather than the StopWatch, unless you're under jdk 1.4,
where the System.nanoTime() method does not exist.
Cheers,
Sébastien
[1]http://www.springframework.org/docs/api/org/springframework/util/StopWatch.html
Sebastien Pennec wrote:
> Martin,
>
> Sorry for the misreading of your code.
>
> Measuring a complete log is actually a good idea. I was pointing this because you
> mentioned that you had trouble obtaining consistent results, which I had not using
> my code. This and the first "dry" run were the two main differences between your code
> and mine.
>
> Cheers,
>
> Sébastien
>
--
Sébastien Pennec
sebastien at qos.ch
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch/
More information about the slf4j-user
mailing list