Skip to content

Instantly share code, notes, and snippets.

@kortemik
Last active June 8, 2023 10:16
Show Gist options
  • Save kortemik/f530134ef0a0362e11f5f3edd28ce458 to your computer and use it in GitHub Desktop.
Save kortemik/f530134ef0a0362e11f5f3edd28ce458 to your computer and use it in GitHub Desktop.
JUL vs SLF4J
Benchmark Mode Cnt Score Error Units
JULPerf.formatedString thrpt 5 1170537073.077 ± 11865469.257 ops/s
JULPerf.plainString thrpt 5 1168436191.354 ± 16765957.090 ops/s
SLF4JPerf.formatedString thrpt 5 1634403249.682 ± 89411732.491 ops/s
SLF4JPerf.plainString thrpt 5 1597299776.636 ± 58139073.685 ops/s
package com.teragrep.jmh_01;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import java.util.logging.*;
public class JULPerf {
private static final Logger logger = Logger.getLogger(JULPerf.class.getName());
private static final String privateStaticFinalString = "<private static final String>";
@Benchmark
@Fork(value = 1, warmups = 1)
@BenchmarkMode(Mode.Throughput)
public void plainString() {
logger.log(Level.FINEST, "JULPerf__");
}
@Benchmark
@Fork(value = 1, warmups = 1)
@BenchmarkMode(Mode.Throughput)
public void formatedString() {
logger.log(Level.FINEST, "JULPerf__ {0}", privateStaticFinalString);
}
}
package com.teragrep.jmh_01;
public class Main {
public static void main(String[] args) throws Exception {
org.openjdk.jmh.Main.main(args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<groupId>com.teragrep</groupId>
<artifactId>jmh_01</artifactId>
<version>${revision}${sha1}${changelist}</version>
<name>jmh_01</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<revision>0.0.1</revision>
<changelist>-SNAPSHOT</changelist>
<sha1/>
</properties>
<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.35</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.35</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.6</version>
</dependency>
</dependencies>
<build>
<directory>${project.basedir}/target</directory>
<finalName>jmh_01</finalName>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.teragrep.jmh_01.Main
</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<parallel>all</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package com.teragrep.jmh_01;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SLF4JPerf {
private static final Logger LOGGER = LoggerFactory.getLogger(SLF4JPerf.class);
private static final String privateStaticFinalString = "<private static final String>";
@Benchmark
@Fork(value = 1, warmups = 1)
@BenchmarkMode(Mode.Throughput)
public void plainString() {
LOGGER.trace("SLF4JPerf");
}
@Benchmark
@Fork(value = 1, warmups = 1)
@BenchmarkMode(Mode.Throughput)
public void formatedString() {
LOGGER.trace("SLF4JPerf {}", privateStaticFinalString);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment