Skip to content

Instantly share code, notes, and snippets.

@travisdowns
Created December 14, 2016 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travisdowns/c7bebc4176f079ca76f3ad9dc434a776 to your computer and use it in GitHub Desktop.
Save travisdowns/c7bebc4176f079ca76f3ad9dc434a776 to your computer and use it in GitHub Desktop.
package net.tdowns;
import java.util.Arrays;
import org.openjdk.jmh.annotations.Benchmark;
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.Thread)
public class ArrayEqualsBench {
@Param({"1024", "4096", "65536"})
int length;
byte[] b;
byte[] bzero;
char[] c;
char[] czero;
short[] s;
short[] szero;
int[] i;
int[] izero;
long[] l;
long[] lzero;
@Setup
public void setup() {
bzero = new byte[length];
b = new byte[length];
b[length - 1] = 1;
czero = new char[length];
c = new char[length];
c[length - 1] = 1;
szero = new short[length];
s = new short[length];
s[length - 1] = 1;
izero = new int[length];
i = new int[length];
i[length - 1] = 1;
lzero = new long[length];
l = new long[length];
l[length - 1] = 1;
}
@Benchmark
public boolean equalsByte() {
return Arrays.equals(b, bzero);
}
@Benchmark
public boolean equalsChar() {
return Arrays.equals(c, czero);
}
@Benchmark
public boolean equalsShort() {
return Arrays.equals(s, szero);
}
@Benchmark
public boolean equalsInt() {
return Arrays.equals(i, izero);
}
@Benchmark
public boolean equalsLong() {
return Arrays.equals(l, lzero);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment