5 "github.com/anacrolix/missinggo/v2/iter"
6 "github.com/anacrolix/torrent/smartban"
7 "github.com/cespare/xxhash"
12 func benchmarkSmartBanRecordBlock[Sum comparable](b *testing.B, hash func([]byte) Sum) {
13 var cache smartban.Cache[bannableAddr, RequestIndex, Sum]
16 var data [defaultChunkSize]byte
18 b.SetBytes(int64(len(data)))
19 for i := range iter.N(b.N) {
20 cache.RecordBlock(addr, RequestIndex(i), data[:])
24 func BenchmarkSmartBanRecordBlock(b *testing.B) {
25 b.Run("xxHash", func(b *testing.B) {
27 benchmarkSmartBanRecordBlock(b, func(block []byte) uint64 {
29 // xxHash is not cryptographic, and so we're salting it so attackers can't know a priori
30 // where block data collisions are.
36 b.Run("Sha1", func(b *testing.B) {
37 benchmarkSmartBanRecordBlock(b, sha1.Sum)