Skip to content

Commit b5227f4

Browse files
committed
updated bitset test
1 parent cf0598c commit b5227f4

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/benblack86/binary/BitSetTest.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,35 @@
33
import java.util.BitSet;
44

55
public class BitSetTest {
6-
private static final int RUNS = 100000;
6+
private static final int RUNS = 1000000;
77
private static final int NUM_BITS = 64;
8-
// every other bit set
9-
private static long setMask = 0xAAAAAAAAAAAAAAAAl;
8+
private static long data = 0b0011100001101100001000100000010010101010001110000011000000000100l;
109

1110
private static long nativeBitTest() {
12-
long bits = 0;
1311
int found = 0;
14-
bits |= setMask;
1512

1613
long start = System.currentTimeMillis();
1714

1815
for (int bit = 0; bit < NUM_BITS; ++bit) {
19-
if (((bits >>> bit) & 0b1) == 0) {
16+
if (((data >> bit) & 0b1) == 1) {
2017
++found;
2118
}
2219
}
2320

24-
System.out.printf("found: %s\n", found);
21+
long time = System.currentTimeMillis() - start;
22+
23+
//System.out.printf("found: %s\n", found);
2524

26-
return System.currentTimeMillis() - start;
25+
return time;
2726
}
2827

29-
private static long bitsetBitTest() {
28+
private static long bitsetBitTest() {
29+
// setup
3030
BitSet bits = new BitSet(NUM_BITS);
31-
for (int bit = 1; bit < NUM_BITS; bit += 2) {
32-
bits.set(bit);
31+
for (int bit = 0; bit < NUM_BITS; ++bit) {
32+
if (((data >> bit) & 0b1) == 0) {
33+
bits.set(bit);
34+
}
3335
}
3436

3537
long start = System.currentTimeMillis();
@@ -39,9 +41,11 @@ private static long bitsetBitTest() {
3941
++found;
4042
}
4143

42-
System.out.printf("found: %s\n", found);
44+
long time = System.currentTimeMillis() - start;
45+
46+
//System.out.printf("found: %s\n", found);
4347

44-
return System.currentTimeMillis() - start;
48+
return time;
4549
}
4650

4751
public static void main(String[] args) {

0 commit comments

Comments
 (0)