Skip to content

Instantly share code, notes, and snippets.

@escholtz
Created January 25, 2018 20:53
Show Gist options
  • Save escholtz/c8cf46eef431a8d7925c91ecda5f0c54 to your computer and use it in GitHub Desktop.
Save escholtz/c8cf46eef431a8d7925c91ecda5f0c54 to your computer and use it in GitHub Desktop.
Bloom Filter Size Estimates
package main
import (
"fmt"
"github.com/willf/bloom"
)
func main() {
items := []uint{10, 100, 1000, 2500, 5000, 10e4, 10e5, 10e6}
falsePositiveRate := []float64{0.01, 0.001, 0.0001}
msg := "%d items, %.4f false positive rate: %d bits, %d hash functions\n"
for _, n := range items {
for _, r := range falsePositiveRate {
m, k := bloom.EstimateParameters(n, r)
fmt.Printf(msg, n, r, m, k)
}
}
}
@escholtz
Copy link
Author

$ go run bloom.go
10 items, 0.0100 false positive rate: 96 bits, 7 hash functions
10 items, 0.0010 false positive rate: 144 bits, 10 hash functions
10 items, 0.0001 false positive rate: 192 bits, 14 hash functions
100 items, 0.0100 false positive rate: 959 bits, 7 hash functions
100 items, 0.0010 false positive rate: 1438 bits, 10 hash functions
100 items, 0.0001 false positive rate: 1918 bits, 14 hash functions
1000 items, 0.0100 false positive rate: 9586 bits, 7 hash functions
1000 items, 0.0010 false positive rate: 14378 bits, 10 hash functions
1000 items, 0.0001 false positive rate: 19171 bits, 14 hash functions
2500 items, 0.0100 false positive rate: 23963 bits, 7 hash functions
2500 items, 0.0010 false positive rate: 35944 bits, 10 hash functions
2500 items, 0.0001 false positive rate: 47926 bits, 14 hash functions
5000 items, 0.0100 false positive rate: 47926 bits, 7 hash functions
5000 items, 0.0010 false positive rate: 71888 bits, 10 hash functions
5000 items, 0.0001 false positive rate: 95851 bits, 14 hash functions
100000 items, 0.0100 false positive rate: 958506 bits, 7 hash functions
100000 items, 0.0010 false positive rate: 1437759 bits, 10 hash functions
100000 items, 0.0001 false positive rate: 1917012 bits, 14 hash functions
1000000 items, 0.0100 false positive rate: 9585059 bits, 7 hash functions
1000000 items, 0.0010 false positive rate: 14377588 bits, 10 hash functions
1000000 items, 0.0001 false positive rate: 19170117 bits, 14 hash functions
10000000 items, 0.0100 false positive rate: 95850584 bits, 7 hash functions
10000000 items, 0.0010 false positive rate: 143775876 bits, 10 hash functions
10000000 items, 0.0001 false positive rate: 191701168 bits, 14 hash functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment