logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r368896 - in /logging/sandbox/log4j/formatter: build.xml pom.xml src/test/java/org/apache/log4j/formatter/Java5PerformanceTest.java src/test/java/org/apache/log4j/formatter/PerformanceTest.java
Date Fri, 13 Jan 2006 22:50:59 GMT
Author: carnold
Date: Fri Jan 13 14:50:54 2006
New Revision: 368896

URL: http://svn.apache.org/viewcvs?rev=368896&view=rev
Log:
Add benchmark tests

Added:
    logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/Java5PerformanceTest.java
    logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/PerformanceTest.java
  (with props)
Modified:
    logging/sandbox/log4j/formatter/build.xml
    logging/sandbox/log4j/formatter/pom.xml

Modified: logging/sandbox/log4j/formatter/build.xml
URL: http://svn.apache.org/viewcvs/logging/sandbox/log4j/formatter/build.xml?rev=368896&r1=368895&r2=368896&view=diff
==============================================================================
--- logging/sandbox/log4j/formatter/build.xml (original)
+++ logging/sandbox/log4j/formatter/build.xml Fri Jan 13 14:50:54 2006
@@ -31,6 +31,8 @@
 	  <property name="log4j.jar" value="${M2_REPO}/log4j/log4j/${log4j.version}/log4j-${log4j.version}.jar"/>
 	  <property name="junit.version" value="3.8.1"/>
 	  <property name="junit.jar" value="${M2_REPO}/junit/junit/${junit.version}/junit-${junit.version}.jar"/>
+	  <property name="slf4j.version" value="1.0-rc3"/>
+	  <property name="slf4j.jar" value="${M2_REPO}/org/slf4j/slf4j-log4j12/${slf4j.version}/slf4j-log4j12-${slf4j.version}.jar"/>
 	
 	  <target name="clean" description="Remove generated artifacts">
 	  	  <delete dir="${target.dir}"/>
@@ -119,10 +121,10 @@
 	  	 <javac destdir="${test-classes-java2.dir}" 
 	  	           srcdir="src/test/java"
 	  			   includes="**/*.java"
-	  	 	       excludes="**/LogFTest*.java **/LogFTraceTest.java"
+	  	 	       excludes="**/LogFTest*.java **/LogFTraceTest.java **/Java5*.java"
 	  	           source="1.3"
 	  	           target="1.3"
-	  		       classpath="${classes-java2.dir};${log4j.jar};${junit.jar}"/>
+	  		       classpath="${classes-java2.dir};${log4j.jar};${junit.jar};${slf4j.jar}"/>
 	  </target>
 
  	  <target name="testCompile" depends="compile" description="Compile tests for Java 5">
@@ -133,7 +135,7 @@
 	  	 	       excludes="**/LogFTest*.java **/LogFTraceTest.java"
 	  	           source="1.3"
 	  	           target="1.3"
-	  		       classpath="${classes.dir};${log4j.jar};${junit.jar}"/>
+	  		       classpath="${classes.dir};${log4j.jar};${junit.jar};${slf4j.jar}"/>
 		 <javac destdir="${test-classes.dir}" 
 		  	           srcdir="src/test/java"
 		  	 	       includes="**/LogFTest*.java **/LogFTraceTest.java"
@@ -145,7 +147,7 @@
 	  <target name="test" depends="testCompile" description="Run tests for Java 5">
 	    <junit printsummary="yes" 
 	    	fork="yes">
-	  	  <classpath path="${test-classes.dir};${classes.dir};${log4j.jar};${junit.jar}"/>
+	  	  <classpath path="${test-classes.dir};${classes.dir};${log4j.jar};${junit.jar};${slf4j.jar}"/>
 	  	  <formatter type="plain" usefile="false"/>
 	  	  <batchtest>
 	  	    <fileset dir="src/test/java" 
@@ -159,12 +161,12 @@
 	       description="Run tests for Java 2">
 	    <junit printsummary="yes" 
 	    	fork="yes">
-	  	  <classpath path="${test-classes-java2.dir};${classes-java2.dir};${log4j.jar};${junit.jar}"/>
+	  	  <classpath path="${test-classes-java2.dir};${classes-java2.dir};${log4j.jar};${junit.jar};${slf4j.jar}"/>
 	  	  <formatter type="plain" usefile="false"/>
 	  	  <batchtest>
 	  	    <fileset dir="src/test/java" 
 	  	    	includes="**/*.java"
-	  	        excludes="**/LogF*.java **/VectorAppender.java **/LogCapture.java"/>
+	  	        excludes="**/LogF*.java **/VectorAppender.java **/LogCapture.java **/Java5*.java"/>
 	  	  </batchtest>
 	    </junit>
 	  </target>

Modified: logging/sandbox/log4j/formatter/pom.xml
URL: http://svn.apache.org/viewcvs/logging/sandbox/log4j/formatter/pom.xml?rev=368896&r1=368895&r2=368896&view=diff
==============================================================================
--- logging/sandbox/log4j/formatter/pom.xml (original)
+++ logging/sandbox/log4j/formatter/pom.xml Fri Jan 13 14:50:54 2006
@@ -109,6 +109,11 @@
       <artifactId>log4j</artifactId>
       <version>1.2.13</version>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.0-rc3</version>
+    </dependency>
   </dependencies>
   <reporting>
     <plugins>

Added: logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/Java5PerformanceTest.java
URL: http://svn.apache.org/viewcvs/logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/Java5PerformanceTest.java?rev=368896&view=auto
==============================================================================
--- logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/Java5PerformanceTest.java
(added)
+++ logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/Java5PerformanceTest.java
Fri Jan 13 14:50:54 2006
@@ -0,0 +1,85 @@
+package org.apache.log4j.formatter;
+import java.text.MessageFormat;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.FileAppender;
+import org.slf4j.impl.MessageFormatter;
+
+/**
+ * Performance tests for Java 5 specific features.
+ * @author Curt Arnold
+ *
+ */
+public class Java5PerformanceTest extends TestCase {
+	
+	private static final int ITERATIONS = 50000; 
+	/**
+	 * Creates new instance of test.
+	 * @param name test name.
+	 */
+	public Java5PerformanceTest(final String name) {
+		super(name);
+	}
+
+	/**
+	 * Configures log4j.
+	 * @return logger.
+	 */
+	private static Logger initLogger() {
+		LogManager.resetConfiguration();
+		Logger logger = Logger.getLogger("org.apache.log4j.formatter.test");
+		FileAppender appender = new FileAppender();
+		String tmpDir = System.getProperty("java.io.tmpdir");
+		appender.setFile(tmpDir + "/TestPerformance.log");
+		appender.setLayout(new PatternLayout("%m%n"));
+		appender.setAppend(false);
+		appender.activateOptions();
+		Logger.getRootLogger().addAppender(appender);
+		return logger;
+	}
+	/**
+	 * Test java.text.MessageFormat.format.
+	 */
+	public void testMessageFormat() {
+		Logger logger = initLogger();
+		
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			logger.debug(MessageFormat.format("Hello, {0}", "World"));
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("java.text.MessageFormat.format(String, Object): " + String.valueOf(end
- start));
+	}
+
+	/**
+	 * Test java.util.Formatter.format.
+	 */
+	public void testUtilFormatter() {
+		Logger logger = initLogger();		
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			logger.debug(String.format("Hello, %s", "World"));
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("java.util.Formatter: " + String.valueOf(end - start));
+	}
+
+	/**
+	 * Test LogF(Logger, String, Object).
+	 */
+	public void testLogF() {
+		Logger logger = initLogger();		
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			LogF.debug(logger, "Hello, %s", "World");
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("LogF(Logger, String, Object): " + String.valueOf(end - start));
+	}
+		
+
+}

Added: logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/PerformanceTest.java
URL: http://svn.apache.org/viewcvs/logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/PerformanceTest.java?rev=368896&view=auto
==============================================================================
--- logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/PerformanceTest.java
(added)
+++ logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/PerformanceTest.java
Fri Jan 13 14:50:54 2006
@@ -0,0 +1,145 @@
+package org.apache.log4j.formatter;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.varia.NullAppender;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.FileAppender;
+
+/**
+ * Performance tests.
+ * @author Curt Arnold
+ *
+ */
+public class PerformanceTest extends TestCase {
+	
+	private static final int ITERATIONS = 50000; 
+	/**
+	 * Creates new instance of test.
+	 * @param name test name.
+	 */
+	public PerformanceTest(final String name) {
+		super(name);
+	}
+
+	/**
+	 * Configures log4j.
+	 * @return logger.
+	 */
+	private static Logger initLogger() {
+		LogManager.resetConfiguration();
+		Logger logger = Logger.getLogger("org.apache.log4j.formatter.test");
+		FileAppender appender = new FileAppender();
+		String tmpDir = System.getProperty("java.io.tmpdir");
+		appender.setFile(tmpDir + "/TestPerformance.log");
+		appender.setLayout(new PatternLayout("%m%n"));
+		appender.setAppend(false);
+//		NullAppender appender = new NullAppender();
+		appender.activateOptions();
+		Logger.getRootLogger().addAppender(appender);
+		return logger;
+	}
+	
+	public void testSleep() throws Exception {
+	    System.out.println("Sleeping to allow profiler to be started");
+	    Thread.sleep(5000);
+    }
+
+	/**
+	 * Test baseline performance.
+	 */
+	public void testMessageBaseline() {
+		Logger logger = initLogger();
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			logger.debug("Hello, World");
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("\"Hello, World\": " + String.valueOf(end - start));
+	}
+
+	/**
+	 * Test java.text.MessageFormat.format(String, Object[]).
+	 */
+	public void testMessageFormatArray() {
+		Logger logger = initLogger();
+		Object[] vals = new Object[] { "World" };
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			logger.debug(java.text.MessageFormat.format("Hello, {0}", vals));
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("java.text.MessageFormat.format(String, Object[]): " + String.valueOf(end
- start));
+	}
+
+		
+	/**
+	 * Test org.slf4j.impl.MessageFormatter.format(String, Object).
+	 */
+	public void testSLF4JFormatter() {
+		Logger logger = initLogger();
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			logger.debug(org.slf4j.impl.MessageFormatter.format("Hello, {}", "World"));
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("org.slf4j.impl.Formatter.format(String, Object): " + String.valueOf(end
- start));
+	}
+
+	/**
+	 * Test org.slf4j.impl.MessageFormatter.format(String, Object[]).
+	 */
+	public void testSLF4JFormatterArray() {
+		Logger logger = initLogger();
+		Object[] vals = new Object[] { "World" };
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			logger.debug(org.slf4j.impl.MessageFormatter.format("Hello, {}", vals));
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("org.slf4j.impl.Formatter.format(String, Object[]): " + String.valueOf(end
- start));
+	}
+
+	/**
+	 * Test org.slf4j.impl.MessageFormatter.format(String, Object[]).
+	 */
+	public void testSLF4JFormatterArrayCreation() {
+		Logger logger = initLogger();
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			logger.debug(org.slf4j.impl.MessageFormatter.format("Hello, {}", 
+			    new Object[] { "World" }));
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("org.slf4j.impl.Formatter.format(String, new Object[]): " + String.valueOf(end
- start));
+	}
+
+	/**
+	 * Test LogSF.debug(Logger, String, Object).
+	 */
+	public void testLogSF() {
+		Logger logger = initLogger();
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			LogSF.debug(logger, "Hello, {}", "World");
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("LogSF.debug(Logger, String, Object): " + String.valueOf(end - start));
+	}
+
+	/**
+	 * Test LogSF.debug(Logger, String, Object).
+	 */
+	public void testLogMF() {
+		Logger logger = initLogger();
+		long start = System.currentTimeMillis();
+		for (int i = 0; i < ITERATIONS; i++) {
+			LogMF.debug(logger, "Hello, {0}", "World");
+		}
+		long end = System.currentTimeMillis();
+		System.out.println("LogMF.debug(Logger, String, Object): " + String.valueOf(end - start));
+	}
+
+}

Propchange: logging/sandbox/log4j/formatter/src/test/java/org/apache/log4j/formatter/PerformanceTest.java
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message