gobitmapbenchmark

August 22, 2026 ยท View on GitHub

A Go program to compare bitmap implementations. This is not a library.

It measures uncompressed bitsets and two Roaring Bitmap implementations: a pure-Go port, and a cgo wrapper around CRoaring.

Implementations

PackageNotes
github.com/bits-and-blooms/bitsetUncompressed bitset (formerly github.com/willf/bitset)
github.com/RoaringBitmap/roaring/v2Pure Go Roaring bitmaps
github.com/RoaringBitmap/gocroaringcgo wrapper for CRoaring

The older goroar implementation is no longer included. It has been unmaintained since 2014.

Requirements

  • Go 1.24 or later
  • A C compiler (gocroaring uses cgo)
go test -count=1

Usage

Synthetic microbenchmarks (intersection, union, set, contains, count, iterate):

go test -bench . -run '^$' -skip Real -benchmem

Real datasets under realdata/ (census, weather, wikileaks, and sorted variants):

go test -bench BenchmarkReal -run '^$' -benchmem

Serialized size of two random sets (N1=650000 values in [0, 15000000) and N2=650000 values in [0, 100000000)):

go test -run TestSize -v

The real-data files are comma-separated 32-bit integer sets. See realdata/README.md.

Sample results

Recorded with Go 1.24.3 on an Apple M4 Max (darwin/arm64), using bitset v1.25.0, roaring/v2 v2.25.0, and gocroaring v1.0.0 (CRoaring 4.5.0). Numbers are illustrative; run the commands above on your machine.

Serialized size (TestSize)

ImplementationSize
bitset13.709 MB
roaring2.462 MB
gocroaring2.463 MB

Synthetic

Time (ns/op):

Benchmarkbitsetroaringgocroaring
Intersection209,236745,625719,899
IntersectionDense26,51963,48445,144
Union801,288994,885921,073
Set3.32018.8449.41
Contains3.29151.5781.81
Count3,55414.7633.02
Iterate161,471246,3121,714,062
SparseIterate878,637196,0742,041,873

Memory (B/op / allocs/op):

Benchmarkbitsetroaringgocroaring
Intersection1,876,006 / 2224,169 / 4818 / 1
IntersectionDense188,449 / 2113,560 / 608 / 1
Union12,501,031 / 22,792,967 / 3,0868 / 1
Set0 / 00 / 04 / 1
Contains0 / 00 / 00 / 0
Count0 / 00 / 00 / 0
Iterate0 / 0112 / 116 / 1
SparseIterate0 / 0112 / 116 / 1

Real data

Each table compares pure-Go roaring with cgo gocroaring on one dataset.

census-income

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating16,589,09716,199,1609,031,8903,3929,330201
clone342,794326,8332,353,3363,3922,537201
iterate31,280,922213,813,40822,4003,200200200
toArray5,879,0464,960,54028,083,32928,083,321201201
pairwise AND1,584,3711,211,4603,065,4011,5923,824199
pairwise OR1,532,9101,248,3133,624,3781,5922,808199
fast OR389,339324,92342,4641,800242

census-income_srt

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating15,796,84214,681,8919,082,3423,39210,076201
clone121,144194,735540,3763,3922,383201
iterate21,827,623188,387,39622,4003,200200200
toArray3,729,0853,169,31124,748,39724,748,372201201
pairwise AND451,692339,413647,6131,5923,567199
pairwise OR5,222,479772,51927,072,0481,59219,157199
fast OR178,874126,71153,0561,800292

census1881

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating3,500,3243,553,9996,499,9423,39212,940201
clone338,981354,8902,103,4823,3923,929201
iterate2,979,83631,061,33222,4003,200200200
toArray598,546495,6954,068,2454,068,240200200
pairwise AND26,135159,06145,8641,592450199
pairwise OR3,882,3821,132,14023,262,3001,59218,938199
fast OR2,608,709671,6152,018,8791,8004642

census1881_srt

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating2,842,8992,414,9332,213,2173,39216,165201
clone131,131235,569316,1733,3926,077201
iterate2,745,23321,508,57022,4003,200200200
toArray545,365470,3292,776,3552,776,353200200
pairwise AND21,580164,36139,8881,592923199
pairwise OR330,432351,363707,5421,59212,068199
fast OR627,913255,945821,8711,8005612

uscensus2000

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating167,577324,584233,2983,3926,342201
clone82,810233,873145,2893,3925,443201
iterate36,179293,38122,4003,200200200
toArray14,46422,50225,96825,968200200
pairwise AND6,680156,67716,4821,592241199
pairwise OR196,919334,682411,5971,59210,724199
fast OR109,795487,36265,8321,8001,7002

weather_sept_85

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating34,691,75034,815,91132,349,5973,39230,529201
clone1,136,5052,247,5179,054,9553,3926,713201
iterate56,461,092402,331,66722,4003,200200200
toArray11,228,98210,445,02351,990,91451,990,902200200
pairwise AND5,280,9024,825,9243,543,4171,5926,194199
pairwise OR5,703,9055,320,25615,048,2261,5928,606199
fast OR2,003,2371,827,189132,7201,800732

weather_sept_85_srt

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating42,762,40740,305,88526,052,2293,39227,368201
clone271,905323,073838,6153,3925,337201
iterate57,588,646498,351,90322,4003,200200200
toArray8,684,7558,600,31164,914,54164,914,419202201
pairwise AND811,007534,931588,6631,5926,350199
pairwise OR3,028,1851,060,8997,484,3881,59220,812199
fast OR124,60856,112146,3461,8001772

wikileaks-noquotes

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating2,440,1031,882,9332,238,9453,39221,541201
clone118,397268,028311,3083,3924,785201
iterate1,344,5858,840,03122,4003,200200200
toArray382,020343,9921,168,5161,168,522200200
pairwise AND165,292299,45186,2801,5922,220199
pairwise OR1,400,975448,1174,754,7221,59221,235199
fast OR110,94472,997186,7131,8001012

wikileaks-noquotes_srt

Operationroaring ns/opgocroaring ns/oproaring B/opgocroaring B/oproaring allocsgocroaring allocs
creating1,489,0741,534,8881,487,4533,39214,566201
clone73,449247,063149,9133,3924,151201
iterate1,122,3148,933,27422,4003,200200200
toArray234,169219,9901,206,2591,206,261200200
pairwise AND50,258248,17769,0401,5921,485199
pairwise OR3,046,920363,32018,377,3631,59219,775199
fast OR105,92355,411296,0741,8003452