Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jmh benchmark submodule #109

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions jmh-benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
To run a benchmark, build the module with:

```
mvn -am -pl jmh-benchmarks package
```

and run

```
java -classpath jmh-benchmarks/target/semantic-metrics-jmh-benchmarks.jar org.openjdk.jmh.Main [arguments]
```

add `-h` to see all possible arguments for JMH, and `-l` to list the benchmarks.
102 changes: 102 additions & 0 deletions jmh-benchmarks/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.spotify.metrics</groupId>
<artifactId>semantic-metrics-parent</artifactId>
<version>1.1.9-SNAPSHOT</version>
</parent>

<artifactId>semantic-metrics-jmh-benchmarks</artifactId>

<properties>
<jmh.version>1.23</jmh.version>
</properties>

<dependencies>
<dependency>
<groupId>com.spotify.metrics</groupId>
<artifactId>semantic-metrics-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<useBaseVersion>false</useBaseVersion>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>default-jar</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (C) 2021 Spotify AB.
*
* 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 com.spotify.metrics.jmh;

import com.codahale.metrics.Histogram;
import com.spotify.metrics.core.Distribution;
import com.spotify.metrics.core.SemanticMetricBuilder;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Group;
import org.openjdk.jmh.annotations.GroupThreads;
import org.openjdk.jmh.annotations.Measurement;
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.annotations.Warmup;

import java.util.concurrent.TimeUnit;

@State(Scope.Group)
@BenchmarkMode(Mode.All)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Fork(value = 2, warmups = 1)
@Measurement(time = 10, iterations = 5)
@Warmup(time = 10, iterations = 2)
public class DistributionBenchmark {

private Distribution distribution;
private Histogram histogram;

@Setup
public void setUp() {
distribution = SemanticMetricBuilder.DISTRIBUTION.newMetric();
histogram = SemanticMetricBuilder.HISTOGRAMS.newMetric();
}

@Benchmark
@Group("dist1")
@GroupThreads(1)
public void distThreads1() {
distribution.record(42.0);
}

@Benchmark
@Group("dist2")
@GroupThreads(2)
public void dist2() {
distribution.record(42.0);
}

@Benchmark
@Group("dist4")
@GroupThreads(4)
public void distThreads4() {
distribution.record(42.0);
}

@Benchmark
@Group("dist8")
@GroupThreads(8)
public void distThreads8() {
distribution.record(42.0);
}
@Benchmark
@Group("hist1")
@GroupThreads(1)
public void histThreads1() {
histogram.update(42);
}

@Benchmark
@Group("hist2")
@GroupThreads(2)
public void hist2() {
histogram.update(42);
}

@Benchmark
@Group("hist4")
@GroupThreads(4)
public void histThreads4() {
histogram.update(42);
}

@Benchmark
@Group("hist8")
@GroupThreads(8)
public void histThreads8() {
histogram.update(42);
}

}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<module>ffwd-reporter</module>
<module>examples</module>
<module>guava</module>
<module>jmh-benchmarks</module>
<module>remote</module>
<module>semantic-metrics-bom</module>
</modules>
Expand Down