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 2014/05/26 01:02:17 UTC

svn commit: r1597485 - /logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java

Author: rpopma
Date: Sun May 25 23:02:17 2014
New Revision: 1597485

URL: http://svn.apache.org/r1597485
Log:
ported SimplePerfTest to JMH

Added:
    logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java   (with props)

Added: logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java?rev=1597485&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java (added)
+++ logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java Sun May 25 23:02:17 2014
@@ -0,0 +1,117 @@
+/*
+ * 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.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.logic.BlackHole;
+
+/**
+ * Tests the overhead of disabled logging.
+ */
+// ============================== HOW TO RUN THIS TEST: ====================================
+//
+// In sampling mode (latency test):
+// java -jar log4j-perf/target/microbenchmarks.jar ".*SimpleBenchmark.*" -f 1 -wi 5 -i 5
+//
+// Usage help:
+// java -jar log4j-perf/target/microbenchmarks.jar -help
+//
+@State(Scope.Thread)
+public class SimpleBenchmark {
+    private static final String msg = "This is a test";
+    private Logger logger;
+
+    @Setup
+    public void setup() {
+        final Configuration config = ((LoggerContext) LogManager.getContext()).getConfiguration();
+        if (!DefaultConfiguration.DEFAULT_NAME.equals(config.getName())) {
+            System.out.println("Configuration was " + config.getName());
+            ((LoggerContext) LogManager.getContext()).start(new DefaultConfiguration());
+        }
+        logger = LogManager.getLogger(SimpleBenchmark.class.getName());
+    }
+
+    @BenchmarkMode(Mode.Throughput)
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    @GenerateMicroBenchmark
+    public void testBaselineThroughput(BlackHole bh) {
+    }
+
+    @BenchmarkMode(Mode.Throughput)
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    @GenerateMicroBenchmark
+    public void testIsDebugEnabledThroughput(BlackHole bh) {
+        bh.consume(logger.isDebugEnabled());
+    }
+
+    @BenchmarkMode(Mode.Throughput)
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    @GenerateMicroBenchmark
+    public void testIsEnabledLevelThroughput(BlackHole bh) {
+        bh.consume(logger.isEnabled(Level.DEBUG));
+    }
+
+    @BenchmarkMode(Mode.Throughput)
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    @GenerateMicroBenchmark
+    public void testDebugDisabledThroughput(BlackHole bh) {
+        logger.debug(msg);
+    }
+
+
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    @GenerateMicroBenchmark
+    public void testBaselineResponseTime(BlackHole bh) {
+    }
+
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    @GenerateMicroBenchmark
+    public void testIsDebugEnabledResponseTime(BlackHole bh) {
+        bh.consume(logger.isDebugEnabled());
+    }
+
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    @GenerateMicroBenchmark
+    public void testIsEnabledLevelResponseTime(BlackHole bh) {
+        bh.consume(logger.isEnabled(Level.DEBUG));
+    }
+
+    @BenchmarkMode(Mode.SampleTime)
+    @OutputTimeUnit(TimeUnit.NANOSECONDS)
+    @GenerateMicroBenchmark
+    public void testDebugDisabledResponseTime(BlackHole bh) {
+        logger.debug(msg);
+    }
+}

Propchange: logging/log4j/log4j2/trunk/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleBenchmark.java
------------------------------------------------------------------------------
    svn:eol-style = native