BitSet VS boolean VS Boolean VS long对比

1.内存占用

Boolean[] uses about 4-20 bytes per boolean value.
boolean[] uses about 1 byte per boolean value.
BitSet uses about 1 bit per boolean value.
long  uses about 1 bit per boolean value.

显眼Boolean[]和boolean[]的空闲占用几乎(BitSet的size比实际指定的要大)是BitSet的8倍

2.cpu占用

for size 1 million boolean[] is about four times faster than BitSet 。

long无论哪种数量级别都比BitSet的get速度快接近4倍

3.便捷性

BitSet具有set方法,使用方便,并且容量可以比long更大


参考文档:

http://stackoverflow.com/questions/8804435/alternative-to-java-bitset-with-array-like-performance

http://imagenious.wordpress.com/2008/02/05/java-bitset-vs-primitive/

你可能感兴趣的:(BitSet VS boolean VS Boolean VS long对比)