[logback-dev] svn commit: r2290 - in logback/trunk/logback-classic: . src/test/java/ch/qos/logback/classic/issue/lbclassic36
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Sun Jun 14 21:22:01 CEST 2009
Author: ceki
Date: Sun Jun 14 21:22:00 2009
New Revision: 2290
Added:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic36/
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic36/TestDateFormat.java
Modified:
logback/trunk/logback-classic/pom.xml
Log:
LBCLASSIC-36 Test performance of Yoda time compared to
SimpleDateFormat.
Here are sample results on my machine:
Raw Joda: average tick 2714.052123 nanoseconds
Sync SimpleDateFormat: average tick 2129.857639 nanoseconds
Raw SimpleDateFormat: average tick 2138.306659 nanoseconds
Conclusion: Yoda time and SimpleDataFormat have roughly equivalent
performace, with the latter having the edge.
Modified: logback/trunk/logback-classic/pom.xml
==============================================================================
--- logback/trunk/logback-classic/pom.xml (original)
+++ logback/trunk/logback-classic/pom.xml Sun Jun 14 21:22:00 2009
@@ -51,7 +51,7 @@
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@@ -134,6 +134,13 @@
</exclusion>
</exclusions>
</dependency>
+
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>1.6</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -151,10 +158,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
- </archive>
+ <configuration>
+ <archive>
+ <manifestFile>
+ ${project.build.outputDirectory}/META-INF/MANIFEST.MF
+ </manifestFile>
+ </archive>
</configuration>
<executions>
<execution>
@@ -191,21 +200,23 @@
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
- <goals>
+ <goals>
<goal>manifest</goal>
- </goals>
+ </goals>
</execution>
</executions>
<configuration>
<instructions>
<Export-Package>ch.qos.logback.classic.*</Export-Package>
<Export-Package>org.slf4j.impl;version=1.5.6</Export-Package>
- <Import-Package>sun.reflect;resolution:=optional,
- javax.jms;resolution:=optional,
- *
+ <Import-Package>
+ sun.reflect;resolution:=optional, javax.jms;resolution:=optional,
+ *
</Import-Package>
- <Bundle-RequiredExecutionEnvironment>J2SE-1.5</Bundle-RequiredExecutionEnvironment>
+ <Bundle-RequiredExecutionEnvironment>
+ J2SE-1.5
+ </Bundle-RequiredExecutionEnvironment>
</instructions>
</configuration>
</plugin>
Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic36/TestDateFormat.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbclassic36/TestDateFormat.java Sun Jun 14 21:22:00 2009
@@ -0,0 +1,63 @@
+package ch.qos.logback.classic.issue.lbclassic36;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
+public class TestDateFormat {
+ public static final String ISO8601_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS";
+ static final long NANOS_IN_ONE_SEC = 1000 * 1000 * 1000L;
+
+ static long RUN_LENGTH = 1000*1000;
+
+ public static void main(String[] args) {
+ for (int i = 0; i < 5; i++) {
+ doRawJoda();
+ doRawSimpleDateFormat();
+ doSyncronizedSimpleDateFormat();
+ }
+
+ print("Raw Joda: ", doRawJoda());
+ print("Sync SimpleDateFormat: ", doSyncronizedSimpleDateFormat());
+ print("Raw SimpleDateFormat: ", doRawSimpleDateFormat());
+ }
+
+ static void print(String msg, double avg) {
+ System.out.println(msg + " average tick " + avg + " nanoseconds");
+ }
+
+ static double doRawJoda() {
+ DateTimeFormatter jodaFormat = DateTimeFormat.forPattern(ISO8601_PATTERN);
+ long timeInMillis = new Date().getTime();
+ long start = System.nanoTime();
+ for (int i = 0; i < RUN_LENGTH; ++i) {
+ jodaFormat.print(timeInMillis);
+ }
+ return (System.nanoTime() - start) * 1.0d / RUN_LENGTH;
+ }
+
+ static double doRawSimpleDateFormat() {
+ SimpleDateFormat simpleFormat = new SimpleDateFormat(ISO8601_PATTERN);
+ long timeInMillis = new Date().getTime();
+ long start = System.nanoTime();
+ for (int i = 0; i < RUN_LENGTH; ++i) {
+ simpleFormat.format(timeInMillis);
+ }
+ return (System.nanoTime() - start) * 1.0d / RUN_LENGTH;
+ }
+
+ static double doSyncronizedSimpleDateFormat() {
+ SimpleDateFormat simpleFormat = new SimpleDateFormat(ISO8601_PATTERN);
+ long timeInMillis = new Date().getTime();
+ long start = System.nanoTime();
+ for (int i = 0; i < RUN_LENGTH; ++i) {
+ synchronized (simpleFormat) {
+ simpleFormat.format(timeInMillis);
+ }
+ }
+ return (System.nanoTime() - start) * 1.0d / RUN_LENGTH;
+ }
+
+}
More information about the logback-dev
mailing list