You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2015/08/17 16:40:16 UTC

logging-log4j2 git commit: updated TimeFormat benchmark to include FastDateFormat

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 011f2c787 -> f672e2834


updated TimeFormat benchmark to include FastDateFormat

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f672e283
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f672e283
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f672e283

Branch: refs/heads/master
Commit: f672e28341b63e076317adb6ff4e60c279c967b4
Parents: 011f2c7
Author: rpopma <rp...@apache.org>
Authored: Mon Aug 17 23:40:22 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Mon Aug 17 23:40:22 2015 +0900

----------------------------------------------------------------------
 .../log4j/perf/jmh/TimeFormatBenchmark.java     | 26 +++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f672e283/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
index 17e6335..bbdee4d 100644
--- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java
@@ -24,6 +24,7 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.logging.log4j.core.util.datetime.FastDateFormat;
 import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.BenchmarkMode;
 import org.openjdk.jmh.annotations.Mode;
@@ -49,6 +50,7 @@ import org.openjdk.jmh.annotations.State;
 public class TimeFormatBenchmark {
 
     SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
+    FastDateFormat fastDateFormat = FastDateFormat.getInstance("HH:mm:ss.SSS");
     long midnightToday = 0;
     long midnightTomorrow = 0;
 
@@ -77,7 +79,7 @@ public class TimeFormatBenchmark {
     }
 
     public static void main(final String[] args) {
-        System.out.println(new TimeFormatBenchmark().customFastFormatString(new BufferState()));
+        System.out.println(new TimeFormatBenchmark().customBitFiddlingFormatString(new BufferState()));
         System.out.println(new TimeFormatBenchmark().customFormatString(new BufferState()));
     }
 
@@ -108,7 +110,25 @@ public class TimeFormatBenchmark {
     @Benchmark
     @BenchmarkMode(Mode.SampleTime)
     @OutputTimeUnit(TimeUnit.NANOSECONDS)
-    public String customFastFormatString(final BufferState state) {
+    public String fastDateFormatString() {
+        return fastDateFormat.format(new Date());
+    }
+
+    @Benchmark
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    public int fastDateFormatBytes(final BufferState state) {
+        final String str = fastDateFormat.format(new Date());
+        final byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
+        state.buffer.clear();
+        state.buffer.put(bytes);
+        return state.buffer.position();
+    }
+
+    @Benchmark
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    public String customBitFiddlingFormatString(final BufferState state) {
         state.buffer.clear();
         fastFormat(System.currentTimeMillis(), state.buffer);
         return new String(state.buffer.array(), 0, state.buffer.position(), StandardCharsets.UTF_8);
@@ -117,7 +137,7 @@ public class TimeFormatBenchmark {
     @Benchmark
     @BenchmarkMode(Mode.SampleTime)
     @OutputTimeUnit(TimeUnit.NANOSECONDS)
-    public int customFastFormatBytes(final BufferState state) {
+    public int customBitFiddlingFormatBytes(final BufferState state) {
         state.buffer.clear();
         fastFormat(System.currentTimeMillis(), state.buffer);
         return state.buffer.position();