8 "github.com/anacrolix/missinggo/v2/iter"
9 "github.com/cespare/xxhash"
11 "github.com/anacrolix/torrent/smartban"
14 func benchmarkSmartBanRecordBlock[Sum comparable](b *testing.B, hash func([]byte) Sum) {
15 var cache smartban.Cache[bannableAddr, RequestIndex, Sum]
18 var data [defaultChunkSize]byte
20 b.SetBytes(int64(len(data)))
21 for i := range iter.N(b.N) {
22 cache.RecordBlock(addr, RequestIndex(i), data[:])
26 func BenchmarkSmartBanRecordBlock(b *testing.B) {
27 b.Run("xxHash", func(b *testing.B) {
29 benchmarkSmartBanRecordBlock(b, func(block []byte) uint64 {
31 // xxHash is not cryptographic, and so we're salting it so attackers can't know a priori
32 // where block data collisions are.
38 b.Run("Sha1", func(b *testing.B) {
39 benchmarkSmartBanRecordBlock(b, sha1.Sum)