logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1394692 - /logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java
Date Fri, 05 Oct 2012 17:51:15 GMT
Author: rgoers
Date: Fri Oct  5 17:51:14 2012
New Revision: 1394692

URL: http://svn.apache.org/viewvc?rev=1394692&view=rev
Log:
Add object creation test

Modified:
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java?rev=1394692&r1=1394691&r2=1394692&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/ReflectionComparison.java
Fri Oct  5 17:51:14 2012
@@ -18,10 +18,14 @@ package org.apache.logging.log4j;
 
 import org.apache.logging.log4j.core.Timer;
 import org.apache.logging.log4j.core.helpers.Loader;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.message.StringFormattedMessage;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import sun.reflect.Reflection;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
@@ -37,6 +41,8 @@ public class ReflectionComparison {
 
     private static final int COUNT = 1000000;
 
+    private static Class[] paramTypes = new Class[] {String.class, Object[].class};
+
     @BeforeClass
     public static void setupCallerCheck() {
         try {
@@ -82,6 +88,29 @@ public class ReflectionComparison {
         System.out.println(timer.toString());
     }
 
+
+    @Test
+    public void createObjects() throws Exception {
+        Timer timer = new Timer("NewObject", COUNT);
+        timer.start();
+        Message msg;
+        for (int i = 0; i < COUNT; ++i) {
+            msg = new StringFormattedMessage("Hello %1", i);
+        }
+        timer.stop();
+        System.out.println(timer.toString());
+        Class<? extends Message> clazz = StringFormattedMessage.class;
+
+        timer = new Timer("ReflectionObject", COUNT);
+        timer.start();
+
+        for (int i = 0; i < COUNT; ++i) {
+            createMessage(clazz, "Hello %1", i);
+        }
+        timer.stop();
+        System.out.println(timer.toString());
+    }
+
     private Class getCallerClass(Object[] array) {
         if (getCallerClass != null) {
             try {
@@ -95,4 +124,9 @@ public class ReflectionComparison {
         return null;
     }
 
+    private Message createMessage(Class<? extends Message> clazz, String msg, Object...
params) throws Exception {
+        Constructor constructor = clazz.getConstructor(paramTypes);
+        return (Message) constructor.newInstance(msg, params);
+    }
+
 }



Mime
View raw message