bench_test.go 687 Bytes
Newer Older
Brian Tiger Chow's avatar
Brian Tiger Chow committed
1 2 3 4 5 6
package decision

import (
	"math"
	"testing"

7
	key "github.com/ipfs/go-ipfs/blocks/key"
8
	"github.com/ipfs/go-ipfs/exchange/bitswap/wantlist"
9
	"github.com/ipfs/go-ipfs/thirdparty/testutil"
Jeromy's avatar
Jeromy committed
10
	"gx/ipfs/QmZMehXD2w81qeVJP6r1mmocxwsD7kqAvuzGm2QWDw1H88/go-libp2p/p2p/peer"
Brian Tiger Chow's avatar
Brian Tiger Chow committed
11 12 13 14 15
)

// FWIW: At the time of this commit, including a timestamp in task increases
// time cost of Push by 3%.
func BenchmarkTaskQueuePush(b *testing.B) {
Brian Tiger Chow's avatar
Brian Tiger Chow committed
16
	q := newPRQ()
Brian Tiger Chow's avatar
Brian Tiger Chow committed
17 18 19 20 21
	peers := []peer.ID{
		testutil.RandPeerIDFatal(b),
		testutil.RandPeerIDFatal(b),
		testutil.RandPeerIDFatal(b),
	}
Brian Tiger Chow's avatar
Brian Tiger Chow committed
22
	b.ResetTimer()
Brian Tiger Chow's avatar
Brian Tiger Chow committed
23
	for i := 0; i < b.N; i++ {
24
		q.Push(wantlist.Entry{Key: key.Key(i), Priority: math.MaxInt32}, peers[i%len(peers)])
Brian Tiger Chow's avatar
Brian Tiger Chow committed
25 26
	}
}