49,937
社区成员




public static void test2() {
int capacity = 1024;
int val = 13;
int count = 100000;
long t1 = System.nanoTime();
for (int i = 0; i < count; i++) {
indexFor1(val,capacity);
}
long t2 = System.nanoTime();
System.out.println("& time:"+(t2-t1));
long t3 = System.nanoTime();
for (int i = 0; i < count; i++) {
indexFor2(val,capacity);
}
long t4 = System.nanoTime();
System.out.println("% time:"+(t4-t3));
}
static int indexFor1(int h, int length) {
return h & (length-1);
}
static int indexFor2(int h, int length) {
return h % (length);
}