Created
June 8, 2017 10:54
-
-
Save nimzo6689/8ada8709a85859e809fc4cb474f9dd00 to your computer and use it in GitHub Desktop.
JMH - ArrayListに初期値によるパフォーマンス調査
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
package com.qiita.nimzo6689.bench; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
import java.util.stream.IntStream; | |
import lombok.SneakyThrows; | |
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.Scope; | |
import org.openjdk.jmh.annotations.State; | |
import org.openjdk.jmh.annotations.Warmup; | |
import org.openjdk.jmh.results.format.ResultFormatType; | |
import org.openjdk.jmh.runner.Runner; | |
import org.openjdk.jmh.runner.options.Options; | |
import org.openjdk.jmh.runner.options.OptionsBuilder; | |
/** | |
* | |
* @author ueokaj | |
*/ | |
@State(Scope.Thread) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@Warmup(iterations = 5) | |
@Measurement(iterations = 5) | |
@BenchmarkMode(Mode.AverageTime) | |
@Fork(2) | |
public class ArrayListBenchmark { | |
private static final int size = 100; | |
@Benchmark | |
public void withInitialSize() { | |
List<Integer> sizeList = new ArrayList<>(size); | |
IntStream.range(0, size).forEach(i -> sizeList.add(i)); | |
} | |
@Benchmark | |
public void withoutInitialSize() { | |
List<Integer> defaultList = new ArrayList<>(); | |
IntStream.range(0, size).forEach(i -> defaultList.add(i)); | |
} | |
@SneakyThrows | |
public static void main(String[] args) { | |
Options opt = new OptionsBuilder() | |
.include(ArrayListBenchmark.class.getSimpleName()) | |
.resultFormat(ResultFormatType.CSV) | |
.build(); | |
new Runner(opt).run(); | |
} | |
} |
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
<?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> | |
<groupId>com.qiita.nimzo6689</groupId> | |
<artifactId>MyApp</artifactId> | |
<version>1.0</version> | |
<packaging>jar</packaging> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<maven.compiler.source>1.8</maven.compiler.source> | |
<maven.compiler.target>1.8</maven.compiler.target> | |
</properties> | |
<dependencies> | |
<!-- Utilities --> | |
<dependency> | |
<groupId>org.projectlombok</groupId> | |
<artifactId>lombok</artifactId> | |
<version>1.16.12</version> | |
<scope>provided</scope> | |
</dependency> | |
<!--Tuning--> | |
<dependency> | |
<groupId>org.openjdk.jmh</groupId> | |
<artifactId>jmh-core</artifactId> | |
<version>1.19</version> | |
</dependency> | |
<dependency> | |
<groupId>org.openjdk.jmh</groupId> | |
<artifactId>jmh-generator-annprocess</artifactId> | |
<version>1.19</version> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment