Skip to content

Instantly share code, notes, and snippets.

@chalstrick
Last active May 8, 2019 09:57
Show Gist options
  • Save chalstrick/9bbaf4d314bb32726d5a1ce7331871a4 to your computer and use it in GitHub Desktop.
Save chalstrick/9bbaf4d314bb32726d5a1ce7331871a4 to your computer and use it in GitHub Desktop.
import java.util.Objects;
public class TestHashPerformance {
private static final int N = 10000000;
public static void main(String args[]) {
int r[] = new int[N];
long start = System.currentTimeMillis();
long n1=0, n2=N;
for (int i = 0; i < N; i++) {
r[i] = Objects.hash(Long.valueOf(n1), Long.valueOf(n2));
n1++;
n2--;
}
System.out.println(
"hashing two Long casted from long "
+ N
+ " times took "
+ (System.currentTimeMillis() - start)
+ " mills");
n1=0; n2=N;
start = System.currentTimeMillis();
for (int i = 0; i < N; i++) {
r[i] = (int) (n1 ^ n2);
n1++;
n2--;
}
System.out.println(
" XORing two longs "
+ N
+ " times took "
+ (System.currentTimeMillis() - start)
+ " mills");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment