Add files via upload (#14006)
This commit is contained in:
parent
65f6f416c5
commit
2da5d14e25
|
@ -1,34 +1,41 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>core-java-collections-list-5</artifactId>
|
<artifactId>core-java-collections-list-5</artifactId>
|
||||||
<name>core-java-collections-list-5</name>
|
<name>core-java-collections-list-5</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung.core-java-modules</groupId>
|
<groupId>com.baeldung.core-java-modules</groupId>
|
||||||
<artifactId>core-java-modules</artifactId>
|
<artifactId>core-java-modules</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>jmh-core</artifactId>
|
||||||
<version>${commons-lang.version}</version>
|
<version>1.36</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
<dependency>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<groupId>commons-lang</groupId>
|
||||||
<version>${commons-lang3.version}</version>
|
<artifactId>commons-lang</artifactId>
|
||||||
</dependency>
|
<version>${commons-lang.version}</version>
|
||||||
</dependencies>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
<properties>
|
<groupId>org.apache.commons</groupId>
|
||||||
<commons-lang.version>2.2</commons-lang.version>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
<version>${commons-lang3.version}</version>
|
||||||
</properties>
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jmh.version>1.21</jmh.version>
|
||||||
|
<commons-lang.version>2.2</commons-lang.version>
|
||||||
|
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.baeldung.arrayandlistperformance;
|
||||||
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
public class ArrayAndArrayListPerformance {
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public void arrayCreation() {
|
||||||
|
int[] array = new int[1000000];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public void arrayListCreation() {
|
||||||
|
ArrayList<Integer> list = new ArrayList<>(1000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public void arrayItemSetting() {
|
||||||
|
int[] array = new int[1000000];
|
||||||
|
array[0] = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public void arrayListItemSetting() {
|
||||||
|
ArrayList<Integer> list = new ArrayList<>(1000000);
|
||||||
|
list.add(0, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public void arrayItemRetrieval() {
|
||||||
|
int[] array = new int[1000000];
|
||||||
|
array[0] = 10;
|
||||||
|
int item = array[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public void arrayListItemRetrieval() {
|
||||||
|
ArrayList<Integer> list = new ArrayList<>(1000000);
|
||||||
|
list.add(0, 10);
|
||||||
|
int item2 = list.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public void arrayCloning() {
|
||||||
|
int[] array = new int[1000000];
|
||||||
|
int[] newArray = array.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public void arrayListCloning() {
|
||||||
|
ArrayList<Integer> list = new ArrayList<>(1000000);
|
||||||
|
ArrayList<Integer> newList = new ArrayList<>(list);
|
||||||
|
}
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
org.openjdk.jmh.runner.Runner runner = new org.openjdk.jmh.runner.Runner(new OptionsBuilder()
|
||||||
|
.include(ArrayAndArrayListPerformance.class.getSimpleName())
|
||||||
|
.forks(1)
|
||||||
|
.build());
|
||||||
|
runner.run();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue