Skip to content

Commit

Permalink
Making benchmarks and tests deterministic.
Browse files Browse the repository at this point in the history
By using a fixed seed for the data generated.
  • Loading branch information
panmari committed Aug 10, 2022
1 parent 0e9e5de commit 41baf34
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cuckoofilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package cuckoo

import (
"bufio"
"crypto/rand"
"fmt"
"io"
"math"
"math/rand"
"os"
"testing"

Expand Down Expand Up @@ -104,14 +103,13 @@ func TestFilter_LookupLarge(t *testing.T) {
}

func TestFilter_Insert(t *testing.T) {
const cap = 10000
filter := NewFilter(cap)

var hash [32]byte
filter := NewFilter(10000)
rng := rand.New(rand.NewSource(int64(42)))

hash := make([]byte, 32)
for i := 0; i < 100; i++ {
io.ReadFull(rand.Reader, hash[:])
filter.Insert(hash[:])
rng.Read(hash)
filter.Insert(hash)
}

if got, want := filter.Count(), uint(100); got != want {
Expand All @@ -134,9 +132,10 @@ func BenchmarkFilter_Reset(b *testing.B) {
func benchmarkKeys(b *testing.B, size int) [][]byte {
b.Helper()
keys := make([][]byte, size)
rng := rand.New(rand.NewSource(int64(size)))
for i := range keys {
keys[i] = make([]byte, 32)
if _, err := io.ReadFull(rand.Reader, keys[i]); err != nil {
if _, err := rng.Read(keys[i]); err != nil {
b.Error(err)
}
}
Expand Down

0 comments on commit 41baf34

Please sign in to comment.