Skip to content

@stonegao /LogPerfTest.scala forked from anonymous/LogPerfTest.scala
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
perf test for explicitly checking isDebugEnabled vs passing a closure
import org.apache.log4j.{Logger, Level}
object LogPerfTest {
val logger = Logger.getLogger(this.getClass)
def main(args: Array[String]) {
val stmt = "This is a test log statement"
var iterations = args(0).toInt
for(logLevel <- List(Level.DEBUG, Level.INFO)) {
var i = 0
logger.setLevel(logLevel)
var start = System.nanoTime
while(i < iterations) {
if(logger.isDebugEnabled)
logger.debug(stmt)
i += 1
}
var ellapsed: Double = System.nanoTime - start
System.err.println("ifDebugEnabled with logging = " + logLevel + ": " + (ellapsed / iterations) + " ns per invocation")
System.err.flush()
i = 0
start = System.nanoTime
while(i < iterations) {
debug(stmt)
i += 1
}
ellapsed = System.nanoTime - start
System.err.println("Debug helper with logging = " + logLevel + ": " + (ellapsed / iterations) + " ns per invocation")
System.err.flush()
}
}
def debug(stmt: => String) =
if(logger.isDebugEnabled)
logger.debug(stmt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.