<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div>Hi,<br><br>I had downloaded the logback version 0.9.2 sometime back and had done some performance comparison vis a vis log4j. At that time the tested call (logger.isDebugEnabled) was atleast 3 times faster in logback then log4j. But just today i downloaded the 0.9.5 version and it seems that due to some changes the performance has been hit . Now logback is a bit slower then log4j for the same call . (Although i must add that the performance of parameterized call has improved, and it now takes half of the time as compared to 0.9.2)<br><br>I am pasting the code used for the test.<br><br>- Mandeep<br><br>====================================================================================================<br>====================================================================================================<br><br>package
mandy.test.programs;<br><br>import org.slf4j.Logger;<br>import org.slf4j.LoggerFactory;<br><br>public class LogTester2 {<br><br> static Logger logbacklogger = LoggerFactory.getLogger(LogTester2.class);<br> static org.apache.log4j.Logger log4jlogger = org.apache.log4j.Logger.getLogger(LogTester2.class);<br><br> // How many times should we try to log:<br> static int loop = 1000000;<br><br> public static void main(String[] args) throws InterruptedException {<br> initConfig();<br><br> // Let's run once for Just In Time compiler<br> log4jDirectDebugCall();<br> log4jTestedDebugCall();<br> logbackDirectDebugCall();<br> logbackTestedDebugCall();<br> logbackParametrizedDebugCall();<br><br> // let's run the tests and display the results:<br> long result1 =
log4jDirectDebugCall();<br> long result2 = log4jTestedDebugCall();<br> long result3 = logbackDirectDebugCall();<br> long result4 = logbackTestedDebugCall();<br> long result5 = logbackParametrizedDebugCall();<br><br> System.out.println("###############################################");<br> System.out.println("Log4j direct debug call: " + result1);<br> System.out.println("Log4j tested (isDebugEnabled) debug call: " + result2);<br> System.out.println("Logback direct debug call: " + result3);<br> System.out.println("Logback tested (isDebugEnabled) debug call: " + result4);<br> System.out.println("Logback parametrized debug call: " + result5);<br> System.out.println("###############################################");<br> }<br><br> private static long
log4jDirectDebugCall() {<br> Integer j = new Integer(2);<br> long start = System.nanoTime();<br> for (int i = 0; i < loop; i++ ) {<br> log4jlogger.debug("SEE IF THIS IS LOGGED " + j + ".");<br> }<br> return (System.nanoTime() - start) / loop;<br> }<br><br> private static long log4jTestedDebugCall() {<br> Integer j = new Integer(2);<br> long start = System.nanoTime();<br> for (int i = 0; i < loop; i++ ) {<br> if (log4jlogger.isDebugEnabled()) {<br> log4jlogger.debug("SEE IF THIS IS LOGGED " + j + ".");<br> }<br> }<br> return (System.nanoTime() - start) / loop;<br> }<br><br> private static long logbackDirectDebugCall()
{<br> Integer j = new Integer(2);<br> long start = System.nanoTime();<br> for (int i = 0; i < loop; i++ ) {<br> logbacklogger.debug("SEE IF THIS IS LOGGED " + j + ".");<br> }<br> return (System.nanoTime() - start) / loop;<br> }<br><br> private static long logbackTestedDebugCall() {<br> Integer j = new Integer(2);<br> long start = System.nanoTime();<br> for (int i = 0; i < loop; i++ ) {<br> if (logbacklogger.isDebugEnabled())<br> logbacklogger.debug("SEE IF THIS IS LOGGED " + j + ".");<br> }<br> return (System.nanoTime() - start) / loop;<br> }<br><br> private static long logbackParametrizedDebugCall() {<br> Integer j = new
Integer(2);<br> long start = System.nanoTime();<br> for (int i = 0; i < loop; i++ ) {<br> logbacklogger.debug("SEE IF THIS IS LOGGED {}.", j);<br> }<br> return (System.nanoTime() - start) / loop;<br> }<br><br> private static void initConfig() {<br> org.apache.log4j.Logger log4jRoot = org.apache.log4j.Logger.getRootLogger();<br> log4jRoot.setLevel(org.apache.log4j.Level.INFO);<br><br> ch.qos.logback.classic.Logger lbRoot = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("ROOT");<br> lbRoot.setLevel(ch.qos.logback.classic.Level.INFO);<br><br> // create the loggers<br> org.apache.log4j.Logger.getLogger("perfTest");<br> org.apache.log4j.Logger.getLogger("perfTest.ch");<br>
org.apache.log4j.Logger.getLogger("perfTest.ch.qos");<br> org.apache.log4j.Logger.getLogger("perfTest.ch.qos.logback");<br> LoggerFactory.getLogger("perfTest");<br> LoggerFactory.getLogger("perfTest.ch");<br> LoggerFactory.getLogger("perfTest.ch.qos");<br> LoggerFactory.getLogger("perfTest.ch.qos.logback");<br> }<br><br>}<br><br></div></div><br>
<hr size=1><a href="http://us.rd.yahoo.com/evt=48226/*http://new.toolbar.yahoo.com/toolbar/features/norton/index.php">Get the free Yahoo! toolbar</a> and rest assured with the added security of spyware protection.
</body></html>