Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
376 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
## | ||
## JAVA | ||
## | ||
# Compiled class files # | ||
*.class | ||
|
||
# Log files # | ||
*.log | ||
logs/ | ||
|
||
# Package files # | ||
*.jar | ||
*.war | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
## | ||
## MAVEN | ||
## | ||
# Build folder # | ||
**/target | ||
|
||
## | ||
## IntelliJ | ||
## | ||
# User-specific configuration # | ||
.idea/ | ||
.idea_modules/ | ||
|
||
# Project files | ||
*.iws | ||
*.iml | ||
|
||
# Output folder # | ||
out/ | ||
|
||
## | ||
## Eclipse | ||
## | ||
# User-specific configuration # | ||
local.properties | ||
.metadata | ||
.settings/ | ||
|
||
# Output folder # | ||
bin/ | ||
|
||
# Temporary files # | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
|
||
## | ||
## NetBeans | ||
## | ||
# User-specific configuration # | ||
**/nbproject/** | ||
|
||
# Output folders # | ||
build/ | ||
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
|
||
## | ||
## Linux | ||
## | ||
# Unwanted files and folders # | ||
*~ | ||
.Trash-* | ||
.nfs* | ||
|
||
## | ||
## MacOS | ||
## | ||
# General # | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Unwanted files and folders # | ||
.TemporaryItems | ||
.Trashes | ||
Network Trash Folder | ||
Temporary Items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
# javafilters-benchmarks | ||
# Java filters benchmarks | ||
|
||
|
||
## License | ||
------- | ||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<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> | ||
|
||
<groupId>com.sergeyvolkodav</groupId> | ||
<artifactId>filter-benchmark</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>JMH benchmark for multiple filters</name> | ||
|
||
<prerequisites> | ||
<maven>3.0</maven> | ||
</prerequisites> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
|
||
<jmh.version>1.17.3</jmh.version> | ||
<javac.target>1.8</javac.target> | ||
<uberjar.name>benchmarks</uberjar.name> | ||
|
||
<!--Maven plugins--> | ||
<maven.compiler.plugin.version>3.1</maven.compiler.plugin.version> | ||
<maven.shade.plugin.version>2.2</maven.shade.plugin.version> | ||
<maven.clean.plugin.version>2.5</maven.clean.plugin.version> | ||
<maven.deploy.plugin.version>2.8.1</maven.deploy.plugin.version> | ||
<maven.install.plugin.version>2.5.1</maven.install.plugin.version> | ||
<maven.jar.plugin.version>2.4</maven.jar.plugin.version> | ||
<maven.javadoc.plugin.version>2.9.1</maven.javadoc.plugin.version> | ||
<maven.resources.plugin.version>2.6</maven.resources.plugin.version> | ||
<maven.site.plugin.version>3.3</maven.site.plugin.version> | ||
<maven.source.plugin.version>2.2.1</maven.source.plugin.version> | ||
<maven.surefire.plugin.version>2.17</maven.surefire.plugin.version> | ||
|
||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-core</artifactId> | ||
<version>${jmh.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openjdk.jmh</groupId> | ||
<artifactId>jmh-generator-annprocess</artifactId> | ||
<version>${jmh.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven.compiler.plugin.version}</version> | ||
<configuration> | ||
<compilerVersion>${javac.target}</compilerVersion> | ||
<source>${javac.target}</source> | ||
<target>${javac.target}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>${maven.shade.plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<finalName>${uberjar.name}</finalName> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.openjdk.jmh.Main</mainClass> | ||
</transformer> | ||
</transformers> | ||
<filters> | ||
<filter> | ||
<!-- | ||
Shading signed JARs will fail without this. | ||
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar | ||
--> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>${maven.clean.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>${maven.deploy.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>${maven.install.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>${maven.jar.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>${maven.javadoc.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>${maven.resources.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>${maven.site.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>${maven.source.plugin.version}</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven.surefire.plugin.version}</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.sergeyvolkodav; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.stream.Collectors; | ||
|
||
import org.openjdk.jmh.annotations.Level; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
|
||
@State(Scope.Benchmark) | ||
public class ExecutionPlan { | ||
|
||
private List<Double> doubles; | ||
|
||
@Param({"10", "100", "1000", "10000", "100000", "1000000"}) | ||
int arraySize; | ||
|
||
@Setup(Level.Invocation) | ||
public void setUp() { | ||
doubles = new Random().doubles(arraySize, 1, 4) | ||
.boxed() | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public List<Double> getDoubles() { | ||
return doubles; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.sergeyvolkodav; | ||
|
||
import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@Warmup(iterations = 10) | ||
@Measurement(iterations = 10, time = 200, timeUnit = MILLISECONDS) | ||
public class FilterBenchmark { | ||
|
||
@Benchmark | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public void oneFilter(ExecutionPlan plan, Blackhole blackhole) { | ||
long count = plan.getDoubles() | ||
.stream() | ||
.filter(d -> d < Math.PI | ||
&& d > Math.E | ||
&& d != 3 | ||
&& d != 2) | ||
.count(); | ||
|
||
blackhole.consume(count); | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public void multipleFilters(ExecutionPlan plan, Blackhole blackhole) { | ||
long count = plan.getDoubles() | ||
.stream() | ||
.filter(d -> d > Math.PI) | ||
.filter(d -> d < Math.E) | ||
.filter(d -> d != 3) | ||
.filter(d -> d != 2) | ||
.count(); | ||
|
||
blackhole.consume(count); | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public void oneFilterParallel(ExecutionPlan plan, Blackhole blackhole) { | ||
long count = plan.getDoubles() | ||
.stream() | ||
.parallel() | ||
.filter(d -> d < Math.PI | ||
&& d > Math.E | ||
&& d != 3 | ||
&& d != 2) | ||
.count(); | ||
|
||
blackhole.consume(count); | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public void multipleFiltersParallel(ExecutionPlan plan, Blackhole blackhole) { | ||
long count = plan.getDoubles() | ||
.stream() | ||
.parallel() | ||
.filter(d -> d > Math.PI) | ||
.filter(d -> d < Math.E) | ||
.filter(d -> d != 3) | ||
.filter(d -> d != 2) | ||
.count(); | ||
|
||
blackhole.consume(count); | ||
} | ||
|
||
@Benchmark | ||
@BenchmarkMode(Mode.Throughput) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
public void oldFashionFilters(ExecutionPlan plan, Blackhole blackhole) { | ||
long count = 0; | ||
for (int i = 0; i < plan.getDoubles().size(); i++) { | ||
if (plan.getDoubles().get(i) > Math.PI | ||
&& plan.getDoubles().get(i) > Math.E | ||
&& plan.getDoubles().get(i) != 3 | ||
&& plan.getDoubles().get(i) != 2) { | ||
count = count + 1; | ||
} | ||
} | ||
|
||
blackhole.consume(count); | ||
} | ||
} |