import java.util.BitSet;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class BitSetTest {
/**
* @param args
*/
public static void main(String[] args) {
BitSet bm = new BitSet();
int randomVal = 1000000;
for (int i = 0; i < 1000000; i++) {
bm.set(new Random().nextInt(randomVal));
}
BitSet bm2 = new BitSet();
for (int i = 0; i < 1000000; i++) {
bm2.set(new Random().nextInt(randomVal));
}
long s = System.currentTimeMillis();
bm2.and(bm);
System.out.println(System.currentTimeMillis() - s);
}
}
import java.util.BitSet;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class SetTest {
/**
* @param args
*/
public static void main(String[] args) {
HashSet bm=new HashSet();
int randomVal = 1000000;
for(int i=0;i<1000000;i++){
bm.add(new Random().nextInt(randomVal));
}
Set bm2=new HashSet();
for(int i=0;i<1000000;i++){
bm2.add(new Random().nextInt(randomVal));
}
long s = System.currentTimeMillis();
bm.retainAll(bm2);
System.out.println(bm.size());
System.out.println(bm2.size());
System.out.println(System.currentTimeMillis()-s);
}
}