[LOGBack-dev] svn commit: r499 - in logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net: . testObjectBuilders

noreply.seb at qos.ch noreply.seb at qos.ch
Thu Aug 31 09:40:03 CEST 2006


Author: seb
Date: Thu Aug 31 09:40:02 2006
New Revision: 499

Added:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/NOPOutputStream.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/Builder.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/LoggingEvent2Builder.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/LoggingEventBuilder.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalExtBuilder.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalSerBuilder.java
Modified:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java

Log:
- Improved code readability in the perfs test
- Added an NOPOutputstream

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/NOPOutputStream.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/NOPOutputStream.java	Thu Aug 31 09:40:02 2006
@@ -0,0 +1,14 @@
+package ch.qos.logback.classic.net;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class NOPOutputStream extends OutputStream {
+
+	@Override
+	public void write(int b) throws IOException {
+		// do nothing
+
+	}
+
+}

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java	Thu Aug 31 09:40:02 2006
@@ -1,209 +1,90 @@
 package ch.qos.logback.classic.net;
 
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
 import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
-import java.io.Serializable;
+
+import ch.qos.logback.classic.net.testObjectBuilders.Builder;
+import ch.qos.logback.classic.net.testObjectBuilders.LoggingEvent2Builder;
+import ch.qos.logback.classic.net.testObjectBuilders.LoggingEventBuilder;
+import ch.qos.logback.classic.net.testObjectBuilders.MinimalExtBuilder;
+import ch.qos.logback.classic.net.testObjectBuilders.MinimalSerBuilder;
 
 import junit.framework.TestCase;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.classic.spi.LoggingEvent2;
 
 public class SerializationPerfsTest extends TestCase {
 
-	LoggerContext lc;
-
-	int loopNumber = 10000;
+	ObjectOutputStream oos;
 
+	int loopNumber = 5000;
+	int resetFrequency = 100;
+	
 	/**
 	 * Last results:
 	 * 
-	 * Minimal Object Externalization: median time = 9981 after 10000 writes.
-	 * Minimal Object Serialization: median time = 13127 after 10000 writes.
-	 * Externalization: median time = 14008 after 10000 writes. 
-	 * Serialization: median time = 31320 after 10000 writes..
+	 * Minimal Object Externalization: average time = 6511 after 10000 writes.
+	 * Minimal Object Serialization: average time = 7883 after 10000 writes.
+	 * Externalization: average time = 9641 after 10000 writes. Serialization:
+	 * average time = 25729 after 10000 writes.
 	 */
 
 	public void setUp() throws Exception {
 		super.setUp();
-		lc = new LoggerContext();
+		oos = new ObjectOutputStream(new NOPOutputStream());
 	}
 
 	public void tearDown() throws Exception {
 		super.tearDown();
-		lc = null;
-	}
-
-	public void testWithMinimalExternalization() throws IOException {
-		ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream());
-
-		// first run for just in time compiler
-		for (int i = 0; i < loopNumber; i++) {
-			oos.writeObject(buildEvent(i));
-		}
-
-		// second run
-		Long t1;
-		Long t2;
-		Long total = 0L;
-		int resetFrequency = 20;
-		int counter = 0;
-		for (int i = 0; i < loopNumber; i++) {
-			t1 = System.nanoTime();
-			oos.writeObject(new MinimalExt(i));
-			t2 = System.nanoTime();
-			total += (t2 - t1);
-			oos.flush();
-			if (++counter >= resetFrequency) {
-				oos.reset();
-			}
-		}
-		System.out.println("Minimal Object Externalization: median time = " + total
-				/ loopNumber + " after " + loopNumber + " writes.");
-	}
-
-	public void testWithMinimalSerialization() throws IOException {
-		ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream());
-
-		// first run for just in time compiler
-		for (int i = 0; i < loopNumber; i++) {
-			oos.writeObject(buildEvent(i));
-		}
-
-		// second run
-		Long t1;
-		Long t2;
-		Long total = 0L;
-		int resetFrequency = 20;
-		int counter = 0;
-		for (int i = 0; i < loopNumber; i++) {
-			t1 = System.nanoTime();
-			oos.writeObject(new MinimalSer(i));
-			t2 = System.nanoTime();
-			total += (t2 - t1);
-			oos.flush();
-			if (++counter >= resetFrequency) {
-				oos.reset();
-			}
-		}
-		System.out.println("Minimal Object Serialization: median time = " + total
-				/ loopNumber + " after " + loopNumber + " writes.");
+		oos = null;
 	}
 
-	public void testWithExternalization() throws IOException {
-
-		ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream());
-
+	public void testPerf(Builder builder, String label) throws IOException {
+		
 		// first run for just in time compiler
-		for (int i = 0; i < loopNumber; i++) {
-			oos.writeObject(buildEvent(i));
-		}
-
-		// second run
-		Long t1;
-		Long t2;
-		Long total = 0L;
-		int resetFrequency = 20;
 		int counter = 0;
 		for (int i = 0; i < loopNumber; i++) {
-			t1 = System.nanoTime();
-			oos.writeObject(buildEvent(i));
-			t2 = System.nanoTime();
-			total += (t2 - t1);
+			oos.writeObject(builder.build(i));
 			oos.flush();
 			if (++counter >= resetFrequency) {
 				oos.reset();
 			}
 		}
-		System.out.println("Externalization: median time = " + total / loopNumber
-				+ " after " + loopNumber + " writes.");
-	}
-
-	public void testWithSerialization() throws IOException {
-
-		ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream());
-
-		// first run for just in time compiler
-		for (int i = 0; i < loopNumber; i++) {
-			oos.writeObject(buildEvent2(i));
-		}
 
 		// second run
 		Long t1;
 		Long t2;
 		Long total = 0L;
-		int resetFrequency = 20;
-		int counter = 0;
+		counter = 0;
+		t1 = System.nanoTime();
 		for (int i = 0; i < loopNumber; i++) {
-			t1 = System.nanoTime();
-			oos.writeObject(buildEvent2(i));
-			t2 = System.nanoTime();
-			total += (t2 - t1);
+			oos.writeObject(builder.build(i));
 			oos.flush();
 			if (++counter >= resetFrequency) {
 				oos.reset();
 			}
 		}
-		System.out.println("Serialization: median time = " + total / loopNumber
-				+ " after " + loopNumber + " writes.");
-	}
-
-	private LoggingEvent buildEvent(int i) {
-		LoggingEvent le = new LoggingEvent();
-		le.setLevel(Level.DEBUG);
-		le.setLogger(lc.getLogger(LoggerContext.ROOT_NAME));
-		// 45 characters message
-		le.setMessage("aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i);
-		le.setThreadName("threadName");
-		return le;
-	}
-
-	private LoggingEvent2 buildEvent2(int i) {
-		LoggingEvent2 le = new LoggingEvent2();
-		le.setLevel(Level.DEBUG);
-		le.setLogger(lc.getLogger(LoggerContext.ROOT_NAME));
-		// 45 characters message
-		le.setMessage("aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i);
-		le.setThreadName("threadName");
-		return le;
+		t2 = System.nanoTime();
+		total += (t2 - t1);
+		System.out.println(label+" : average time = "
+				+ total / loopNumber + " after " + loopNumber + " writes.");
 	}
-}
-
-class MinimalExt implements Externalizable {
-
-	private static final long serialVersionUID = -1367146218373963709L;
-
-	String message;
 
-	public MinimalExt(int i) {
-		// 45 characters message
-		message = "aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i;
+	public void testWithMinimalExternalization() throws IOException {
+		Builder builder = new MinimalExtBuilder();
+		testPerf(builder, "Minimal object externalization");
 	}
 
-	public void readExternal(ObjectInput in) throws IOException,
-			ClassNotFoundException {
-		message = (String) in.readObject();
-
+	public void testWithMinimalSerialization() throws IOException {
+		Builder builder = new MinimalSerBuilder();
+		testPerf(builder, "Minimal object serialization");
 	}
 
-	public void writeExternal(ObjectOutput out) throws IOException {
-		out.writeObject(message);
+	public void testWithExternalization() throws IOException {
+		Builder builder = new LoggingEventBuilder();
+		testPerf(builder, "LoggingEvent object externalization");		
 	}
-}
 
-class MinimalSer implements Serializable {
-
-	private static final long serialVersionUID = 2807646397580899815L;
-
-	String message;
-
-	public MinimalSer(int i) {
-		// 45 characters message
-		message = "aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i;
+	public void testWithSerialization() throws IOException {
+		Builder builder = new LoggingEvent2Builder();
+		testPerf(builder, "LoggingEvent object serialization");	
 	}
 }

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/Builder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/Builder.java	Thu Aug 31 09:40:02 2006
@@ -0,0 +1,6 @@
+package ch.qos.logback.classic.net.testObjectBuilders;
+
+public interface Builder {
+
+	Object build(int i);
+}

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/LoggingEvent2Builder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/LoggingEvent2Builder.java	Thu Aug 31 09:40:02 2006
@@ -0,0 +1,18 @@
+package ch.qos.logback.classic.net.testObjectBuilders;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.LoggingEvent2;
+
+public class LoggingEvent2Builder implements Builder {
+
+	public Object build(int i) {
+		LoggingEvent2 le = new LoggingEvent2();
+		le.setLevel(Level.DEBUG);
+		le.setLogger(new LoggerContext().getLogger(LoggerContext.ROOT_NAME));
+		// 45 characters message
+		le.setMessage("aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i);
+		le.setThreadName("threadName");
+		return le;
+	}
+}

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/LoggingEventBuilder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/LoggingEventBuilder.java	Thu Aug 31 09:40:02 2006
@@ -0,0 +1,18 @@
+package ch.qos.logback.classic.net.testObjectBuilders;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.LoggingEvent;
+
+public class LoggingEventBuilder implements Builder {
+
+	public Object build(int i) {
+		LoggingEvent le = new LoggingEvent();
+		le.setLevel(Level.DEBUG);
+		le.setLogger(new LoggerContext().getLogger(LoggerContext.ROOT_NAME));
+		// 45 characters message
+		le.setMessage("aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i);
+		le.setThreadName("threadName");
+		return le;
+	}
+}

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalExtBuilder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalExtBuilder.java	Thu Aug 31 09:40:02 2006
@@ -0,0 +1,37 @@
+package ch.qos.logback.classic.net.testObjectBuilders;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+
+public class MinimalExtBuilder implements Builder {
+
+	public Object build(int i) {
+		return new MinimalExt(i);
+	}
+	
+}
+
+class MinimalExt implements Externalizable {
+
+	private static final long serialVersionUID = -1367146218373963709L;
+
+	String message;
+
+	public MinimalExt(int i) {
+		// 45 characters message
+		message = "aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i;
+	}
+
+	public void readExternal(ObjectInput in) throws IOException,
+			ClassNotFoundException {
+		message = (String) in.readObject();
+
+	}
+
+	public void writeExternal(ObjectOutput out) throws IOException {
+		out.writeObject(message);
+	}
+}

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalSerBuilder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalSerBuilder.java	Thu Aug 31 09:40:02 2006
@@ -0,0 +1,24 @@
+package ch.qos.logback.classic.net.testObjectBuilders;
+
+import java.io.Serializable;
+
+
+public class MinimalSerBuilder implements Builder{
+
+	public Object build(int i) {
+		return new MinimalSer(i);
+	}
+
+}
+
+class MinimalSer implements Serializable {
+
+	private static final long serialVersionUID = 2807646397580899815L;
+
+	String message;
+
+	public MinimalSer(int i) {
+		// 45 characters message
+		message = "aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i;
+	}
+}
\ No newline at end of file



More information about the logback-dev mailing list