[slf4j-dev] svn commit: r1121 - in slf4j/trunk/slf4j-jdk14: . src/test/java/org/slf4j/impl

ceki at slf4j.org ceki at slf4j.org
Fri Aug 29 17:14:02 CEST 2008


Author: ceki
Date: Fri Aug 29 17:14:02 2008
New Revision: 1121

Modified:
   slf4j/trunk/slf4j-jdk14/pom.xml
   slf4j/trunk/slf4j-jdk14/src/test/java/org/slf4j/impl/PerfTest.java

Log:
- use BogoPerf utility. 
- Using System.currentMillis instead of System.nanoTime. The latter is only available in
  JDK 1.5 

Modified: slf4j/trunk/slf4j-jdk14/pom.xml
==============================================================================
--- slf4j/trunk/slf4j-jdk14/pom.xml	(original)
+++ slf4j/trunk/slf4j-jdk14/pom.xml	Fri Aug 29 17:14:02 2008
@@ -27,6 +27,14 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
 		</dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <classifier>tests</classifier>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: slf4j/trunk/slf4j-jdk14/src/test/java/org/slf4j/impl/PerfTest.java
==============================================================================
--- slf4j/trunk/slf4j-jdk14/src/test/java/org/slf4j/impl/PerfTest.java	(original)
+++ slf4j/trunk/slf4j-jdk14/src/test/java/org/slf4j/impl/PerfTest.java	Fri Aug 29 17:14:02 2008
@@ -4,9 +4,12 @@
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.helpers.BogoPerf;
 
 public class PerfTest extends TestCase {
 
+  static long REFERENCE_BIPS = 9324;
+
   public PerfTest(String name) {
     super(name);
   }
@@ -20,25 +23,30 @@
   }
 
   public void testBug72() {
-    Logger logger = LoggerFactory.getLogger(PerfTest.class);
-    int len = 2000;
-    for (int i = 0; i < len; i++) {
-      logger.debug("hello");
-    }
     
+    int LEN = 1000*1000*10;
+    debugLoop(LEN); // warm up
+    double avg = debugLoop(LEN);
+    long referencePerf = 93;
+    BogoPerf.assertDuration(avg, referencePerf, REFERENCE_BIPS);
+
+    // when the code is guarded by a logger.isLoggable condition,
+    // duration is about 16 *micro*seconds for 1000 iterations
+    // when it is not guarded the figure is 90 milliseconds,
+    // i.e a ration of 1 to 5000
+  }
+
+  double debugLoop(int len) {
+    Logger logger = LoggerFactory.getLogger(PerfTest.class);
     long start = System.currentTimeMillis();
     for (int i = 0; i < len; i++) {
       logger.debug("hello");
     }
 
     long end = System.currentTimeMillis();
-    
-    long duration = end-start;
-    // when the code is guarded by a logger.isLoggable condition, 
-    // duration is about 16 *micro*seconds for 1000 iterations
-    // when it is not guarded the figure is 90 milliseconds,
-    // i.e a ration of 1 to 5000
-    assertTrue(duration <= 5);
+
+    long duration = end - start;
+    return duration;
   }
 
 }



More information about the slf4j-dev mailing list