bench_test.go 639 Bytes
Newer Older
Brian Tiger Chow's avatar
Brian Tiger Chow committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package decision

import (
	"math"
	"testing"

	"github.com/jbenet/go-ipfs/exchange/bitswap/wantlist"
	"github.com/jbenet/go-ipfs/p2p/peer"
	"github.com/jbenet/go-ipfs/util"
	"github.com/jbenet/go-ipfs/util/testutil"
)

// 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 24 25 26
	for i := 0; i < b.N; i++ {
		q.Push(wantlist.Entry{Key: util.Key(i), Priority: math.MaxInt32}, peers[i%len(peers)])
	}
}