Jira BAEL-4211 (#11193)
* Init * Removing mvnw files * Apply eclipse code format * Refactoring * Refactoring * BAEL-4211 Add benchmarks * Delete hexagonal directory * Refactoring based on the feedback * Refactoring based on feedback - package rename * Directory rename Co-authored-by: asia <joannakrzeklubowiecka@protonmail.com>
This commit is contained in:
parent
141a837679
commit
6a638120dc
|
@ -26,10 +26,50 @@
|
||||||
<version>${assertj-core.version}</version>
|
<version>${assertj-core.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<assertj-core.version>3.10.0</assertj-core.version>
|
<assertj-core.version>3.10.0</assertj-core.version>
|
||||||
|
<jmh.version>1.33</jmh.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.baeldung.copyarraymethodsperformance.BenchmarkRunner</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.baeldung.copyarraymethodsperformance;
|
||||||
|
|
||||||
|
public class BenchmarkRunner {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
|
org.openjdk.jmh.Main.main(args);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.baeldung.copyarraymethodsperformance;
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@State(Scope.Thread)
|
||||||
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
@Warmup(iterations = 10)
|
||||||
|
@Fork(1)
|
||||||
|
@Measurement(iterations = 100)
|
||||||
|
public class ObjectsCopyBenchmark {
|
||||||
|
|
||||||
|
@Param({ "10", "1000000" })
|
||||||
|
public int SIZE;
|
||||||
|
Integer[] src;
|
||||||
|
|
||||||
|
@Setup
|
||||||
|
public void setup() {
|
||||||
|
Random r = new Random();
|
||||||
|
src = new Integer[SIZE];
|
||||||
|
|
||||||
|
for (int i = 0; i < SIZE; i++) {
|
||||||
|
src[i] = r.nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public Integer[] systemArrayCopyBenchmark() {
|
||||||
|
Integer[] target = new Integer[SIZE];
|
||||||
|
System.arraycopy(src, 0, target, 0, SIZE);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public Integer[] arraysCopyOfBenchmark() {
|
||||||
|
return Arrays.copyOf(src, SIZE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.baeldung.copyarraymethodsperformance;
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@State(Scope.Thread)
|
||||||
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
@Warmup(iterations = 10)
|
||||||
|
@Fork(1)
|
||||||
|
@Measurement(iterations = 100)
|
||||||
|
public class PrimitivesCopyBenchmark {
|
||||||
|
|
||||||
|
@Param({ "10", "1000000" })
|
||||||
|
public int SIZE;
|
||||||
|
|
||||||
|
int[] src;
|
||||||
|
|
||||||
|
@Setup
|
||||||
|
public void setup() {
|
||||||
|
Random r = new Random();
|
||||||
|
src = new int[SIZE];
|
||||||
|
|
||||||
|
for (int i = 0; i < SIZE; i++) {
|
||||||
|
src[i] = r.nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public int[] systemArrayCopyBenchmark() {
|
||||||
|
int[] target = new int[SIZE];
|
||||||
|
System.arraycopy(src, 0, target, 0, SIZE);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public int[] arraysCopyOfBenchmark() {
|
||||||
|
return Arrays.copyOf(src, SIZE);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue