Last active
May 8, 2019 09:57
-
-
Save chalstrick/9bbaf4d314bb32726d5a1ce7331871a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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