Skip to content

Commit

Permalink
8290391: Reduce runtime of java.util package microbenchmarks
Browse files Browse the repository at this point in the history
Reviewed-by: rriggs, redestad
  • Loading branch information
Eric Caspole committed Jul 19, 2022
1 parent bbc5748 commit 2cb659e
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 104 deletions.
8 changes: 7 additions & 1 deletion test/micro/org/openjdk/bench/java/util/ArraysEquals.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,10 +24,13 @@

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 java.util.Arrays;
import java.util.concurrent.TimeUnit;
Expand All @@ -38,6 +41,9 @@
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
@Warmup(iterations = 4, time = 2)
@Measurement(iterations = 4, time = 2)
@Fork(value = 3)
public class ArraysEquals {

public char[] testCharArray1 = "1234567890123456789012345678901234567890123456789012345678901234567890123456789a".toCharArray();
Expand Down
22 changes: 6 additions & 16 deletions test/micro/org/openjdk/bench/java/util/ArraysFill.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,7 @@

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;
Expand All @@ -39,9 +40,12 @@
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@Warmup(iterations = 4, time = 2)
@Measurement(iterations = 4, time = 2)
@Fork(value = 3)
public class ArraysFill {

@Param({"10", "16", "31", "59", "89", "126", "250", "266", "511", "1021", "2047", "2048", "4095", "8195"})
@Param({"16", "31", "250", "266", "511", "2047", "2048", "8195"})
public int size;

public byte[] testByteArray;
Expand All @@ -65,50 +69,36 @@ public void setup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public void testCharFill() {
Arrays.fill(testCharArray, (char) -1);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public void testByteFill() {
Arrays.fill(testByteArray, (byte) -1);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public void testShortFill() {
Arrays.fill(testShortArray, (short) -1);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public void testIntFill() {
Arrays.fill(testIntArray, -1);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public void testLongFill() {
Arrays.fill(testLongArray, -1);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public void testFloatFill() {
Arrays.fill(testFloatArray, (float) -1.0);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public void testDoubleFill() {
Arrays.fill(testDoubleArray, -1.0);
}
Expand Down
76 changes: 5 additions & 71 deletions test/micro/org/openjdk/bench/java/util/ArraysMismatch.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -33,6 +33,7 @@
import javax.crypto.NoSuchPaddingException;
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;
Expand All @@ -45,6 +46,9 @@
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
@Warmup(iterations = 4, time = 2)
@Measurement(iterations = 4, time = 2)
@Fork(value = 3)
public abstract class ArraysMismatch {

@Param({"90", "800"})
Expand Down Expand Up @@ -90,36 +94,26 @@ public void specificSetup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int matches() {
return Arrays.mismatch(left, right_matches);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int differentSubrangeMatches() {
return Arrays.mismatch(left, leftStartRange, leftEndRange, right_matches, rightStartRange, rightEndRange);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchEnd() {
return Arrays.mismatch(left, right_endMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchMid() {
return Arrays.mismatch(left, right_midMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchStart() {
return Arrays.mismatch(left, right_startMismatch);
}
Expand All @@ -146,36 +140,26 @@ public void specificSetup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int matches() {
return Arrays.mismatch(left, right_matches);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int differentSubrangeMatches() {
return Arrays.mismatch(left, leftStartRange, leftEndRange, right_matches, rightStartRange, rightEndRange);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchEnd() {
return Arrays.mismatch(left, right_endMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchMid() {
return Arrays.mismatch(left, right_midMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchStart() {
return Arrays.mismatch(left, right_startMismatch);
}
Expand All @@ -202,36 +186,26 @@ public void specificSetup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int matches() {
return Arrays.mismatch(left, right_matches);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int differentSubrangeMatches() {
return Arrays.mismatch(left, leftStartRange, leftEndRange, right_matches, rightStartRange, rightEndRange);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchEnd() {
return Arrays.mismatch(left, right_endMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchMid() {
return Arrays.mismatch(left, right_midMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchStart() {
return Arrays.mismatch(left, right_startMismatch);
}
Expand All @@ -258,36 +232,26 @@ public void specificSetup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int matches() {
return Arrays.mismatch(left, right_matches);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int differentSubrangeMatches() {
return Arrays.mismatch(left, leftStartRange, leftEndRange, right_matches, rightStartRange, rightEndRange);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchEnd() {
return Arrays.mismatch(left, right_endMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchMid() {
return Arrays.mismatch(left, right_midMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchStart() {
return Arrays.mismatch(left, right_startMismatch);
}
Expand All @@ -314,36 +278,26 @@ public void specificSetup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int matches() {
return Arrays.mismatch(left, right_matches);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int differentSubrangeMatches() {
return Arrays.mismatch(left, leftStartRange, leftEndRange, right_matches, rightStartRange, rightEndRange);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchEnd() {
return Arrays.mismatch(left, right_endMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchMid() {
return Arrays.mismatch(left, right_midMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchStart() {
return Arrays.mismatch(left, right_startMismatch);
}
Expand All @@ -370,36 +324,26 @@ public void specificSetup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int matches() {
return Arrays.mismatch(left, right_matches);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int differentSubrangeMatches() {
return Arrays.mismatch(left, leftStartRange, leftEndRange, right_matches, rightStartRange, rightEndRange);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchEnd() {
return Arrays.mismatch(left, right_endMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchMid() {
return Arrays.mismatch(left, right_midMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchStart() {
return Arrays.mismatch(left, right_startMismatch);
}
Expand All @@ -426,36 +370,26 @@ public void specificSetup() {
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int matches() {
return Arrays.mismatch(left, right_matches);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int differentSubrangeMatches() {
return Arrays.mismatch(left, leftStartRange, leftEndRange, right_matches, rightStartRange, rightEndRange);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchEnd() {
return Arrays.mismatch(left, right_endMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchMid() {
return Arrays.mismatch(left, right_midMismatch);
}

@Benchmark
@Warmup(iterations = 3)
@Measurement(iterations = 3)
public int mismatchStart() {
return Arrays.mismatch(left, right_startMismatch);
}
Expand Down

1 comment on commit 2cb659e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.