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/08 08:00:50 UTC

logging-log4j2 git commit: Added benchmark to test how expensive constructing a varargs array is.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master e579cf7fc -> 293cb1d94


Added benchmark to test how expensive constructing a varargs array is.

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

Branch: refs/heads/master
Commit: 293cb1d94d628d3014a0b7ad039ab8139da35f41
Parents: e579cf7
Author: rpopma <rp...@apache.org>
Authored: Sat Aug 8 15:00:44 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Aug 8 15:00:44 2015 +0900

----------------------------------------------------------------------
 .../log4j/perf/jmh/VarargsBenchmark.java        | 76 ++++++++++++++++++++
 1 file changed, 76 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/293cb1d9/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/VarargsBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/VarargsBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/VarargsBenchmark.java
new file mode 100644
index 0000000..40c00c9
--- /dev/null
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/VarargsBenchmark.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.perf.jmh;
+
+import java.util.concurrent.TimeUnit;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+
+/**
+ * Tests how expensive constructing a varargs array is.
+ */
+// ============================== HOW TO RUN THIS TEST: ====================================
+//
+// single thread:
+// java -jar log4j-perf/target/benchmarks.jar ".*Nanotime.*" -f 1 -wi 5 -i 5
+//
+// multiple threads (for example, 4 threads):
+// java -jar log4j-perf/target/benchmarks.jar ".*Nanotime.*" -f 1 -wi 5 -i 5 -t 4 -si true
+//
+// Usage help:
+// java -jar log4j-perf/target/benchmarks.jar -help
+//
+@State(Scope.Benchmark)
+public class VarargsBenchmark {
+
+    public static void main(final String[] args) {
+    }
+
+    @Benchmark
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    public void baseline() {
+    }
+
+    @Benchmark
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    public long varargParams() {
+        return vararg3Method("example {} {} {}", "one", "two", "three", "four");
+    }
+
+    @Benchmark
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    public long individualParams() {
+        return vararg3Method("example {} {} {}", "one", "two", "three");
+    }
+
+    private long vararg3Method(String string, String... params) {
+        return string.length() + params.length;
+    }
+
+    private long vararg3Method(String string, String param1, String param2, String param3) {
+        return string.length() + param1.length();
+    }
+}