mirror of
https://github.com/luxfi/container.git
synced 2026-09-24 00:24:34 +00:00
38 lines
683 B
Go
38 lines
683 B
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package sampler
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func BenchmarkWeightedWithoutReplacement(b *testing.B) {
|
|
sizes := []int{
|
|
1,
|
|
5,
|
|
25,
|
|
50,
|
|
75,
|
|
100,
|
|
}
|
|
for _, size := range sizes {
|
|
b.Run(fmt.Sprintf("%d elements", size), func(b *testing.B) {
|
|
require := require.New(b)
|
|
s := NewWeightedWithoutReplacement()
|
|
|
|
_, weights, err := CalcWeightedPoW(0, 100000)
|
|
require.NoError(err)
|
|
require.NoError(s.Initialize(weights))
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, _ = s.Sample(size)
|
|
}
|
|
})
|
|
}
|
|
}
|