logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1422199 - /logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatsPerfTest.java
Date Sat, 15 Dec 2012 07:15:55 GMT
Author: rgoers
Date: Sat Dec 15 07:15:54 2012
New Revision: 1422199

URL: http://svn.apache.org/viewvc?rev=1422199&view=rev
Log:
Add FormattedMessage to performance test

Modified:
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatsPerfTest.java

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatsPerfTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatsPerfTest.java?rev=1422199&r1=1422198&r2=1422199&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatsPerfTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/MessageFormatsPerfTest.java
Sat Dec 15 07:15:54 2012
@@ -32,13 +32,14 @@ public class MessageFormatsPerfTest {
     private static long stringTime = 0;
     private static long paramTime = 0;
     private static long msgFormatTime = 0;
+    private static long formattedTime = 0;
 
     @AfterClass
     public static void after() {
         if (stringTime > paramTime) {
             System.out.println(String.format("Parameterized is %1$.2f times faster than StringFormat.",
                 ((float) stringTime / paramTime)));
-        } else if (stringTime > paramTime) {
+        } else if (stringTime < paramTime) {
             System.out.println(String.format("Parameterized is %1$.2f times slower than StringFormat.",
                 ((float) paramTime / stringTime)));
         } else {
@@ -47,12 +48,21 @@ public class MessageFormatsPerfTest {
         if (msgFormatTime > paramTime) {
             System.out.println(String.format("Parameterized is %1$.2f times faster than MessageFormat.",
                 ((float) msgFormatTime / paramTime)));
-        } else if (msgFormatTime > paramTime) {
+        } else if (msgFormatTime < paramTime) {
             System.out.println(String.format("Parameterized is %1$.2f times slower than MessageFormat.",
                 ((float) paramTime / msgFormatTime)));
         } else {
             System.out.println("The speed of Parameterized and MessageFormat are the same");
         }
+        if (formattedTime > paramTime) {
+            System.out.println(String.format("Parameterized is %1$.2f times faster than Formatted.",
+                ((float) formattedTime / paramTime)));
+        } else if (formattedTime < paramTime) {
+            System.out.println(String.format("Parameterized is %1$.2f times slower than Formatted.",
+                ((float) paramTime / formattedTime)));
+        } else {
+            System.out.println("The speed of Parameterized and Formatted are the same");
+        }
     }
 
     @Test
@@ -96,4 +106,18 @@ public class MessageFormatsPerfTest {
         paramTime = timer.getElapsedNanoTime();
         System.out.println(timer.toString());
     }
+
+    @Test
+    public void testFormattedParameterizedPerf() {
+        String testMsg = "Test message {} {}";
+        Timer timer = new Timer("FormattedParameterized", LOOP_CNT);
+        timer.start();
+        for (int i = 0; i < LOOP_CNT; ++i) {
+            FormattedMessage msg = new FormattedMessage(testMsg, "Apache", "Log4j");
+            array[i] = msg.getFormattedMessage();
+        }
+        timer.stop();
+        formattedTime = timer.getElapsedNanoTime();
+        System.out.println(timer.toString());
+    }
 }



Mime
View raw message