2015-05-01 08:28:01 +02:00
|
|
|
// Copyright (c) 2013-2014 The btcsuite developers
|
2014-01-01 17:16:15 +01:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2013-10-26 08:57:00 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"testing"
|
2014-07-02 15:50:08 +02:00
|
|
|
|
2015-02-05 22:16:39 +01:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2013-10-26 08:57:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// BenchmarkMruInventoryList performs basic benchmarks on the most recently
|
|
|
|
// used inventory handling.
|
|
|
|
func BenchmarkMruInventoryList(b *testing.B) {
|
|
|
|
// Create a bunch of fake inventory vectors to use in benchmarking
|
|
|
|
// the mru inventory code.
|
|
|
|
b.StopTimer()
|
|
|
|
numInvVects := 100000
|
2015-02-05 22:16:39 +01:00
|
|
|
invVects := make([]*wire.InvVect, 0, numInvVects)
|
2013-10-26 08:57:00 +02:00
|
|
|
for i := 0; i < numInvVects; i++ {
|
2015-02-05 22:16:39 +01:00
|
|
|
hashBytes := make([]byte, wire.HashSize)
|
2013-10-26 08:57:00 +02:00
|
|
|
rand.Read(hashBytes)
|
2015-02-05 22:16:39 +01:00
|
|
|
hash, _ := wire.NewShaHash(hashBytes)
|
|
|
|
iv := wire.NewInvVect(wire.InvTypeBlock, hash)
|
2013-10-26 08:57:00 +02:00
|
|
|
invVects = append(invVects, iv)
|
|
|
|
}
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
// Benchmark the add plus evicition code.
|
|
|
|
limit := 20000
|
|
|
|
mruInvMap := NewMruInventoryMap(uint(limit))
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
mruInvMap.Add(invVects[i%numInvVects])
|
|
|
|
}
|
|
|
|
}
|