Ejemplo n.º 1
0
func benchmarkChunkMergerWithOutOfOrderChunks(b *testing.B, merger core.ChunkMerger) {
	b.StopTimer()
	chunks := make([]core.Chunk, b.N)
	for i := range chunks {
		chunks[i] = largePackets[i%len(largePackets)]
		chunks[i].Sequence = core.SequenceId(i)
	}
	c := cmwc.MakeGoodCmwc()
	c.Seed(123)
	rng := rand.New(c)
	// Shuffle blocks of 1000 at a time
	for i := 0; i < len(chunks); i += 1000 {
		max := len(chunks)
		if max > 1000 {
			max = 1000
		}
		for j := 0; j < max; j++ {
			swap := rng.Intn(max-j) + j
			chunks[j], chunks[swap] = chunks[swap], chunks[j]
		}
	}
	b.StartTimer()
	for i := range chunks {
		merger.AddChunk(chunks[i])
	}
}
Ejemplo n.º 2
0
func benchmarkChunkMergerWithInOrderChunks(b *testing.B, merger core.ChunkMerger) {
	b.StopTimer()
	chunks := make([]core.Chunk, b.N)
	for i := range chunks {
		chunks[i] = smallPackets[i%len(smallPackets)]
		chunks[i].Sequence = core.SequenceId(i)
	}
	b.StartTimer()
	for i := range chunks {
		merger.AddChunk(chunks[i])
	}
}