Exemplo n.º 1
0
func BenchmarkInsert(b *testing.B) {
	r := rand.New(rand.NewSource(12345))
	data := make([]*A, 1000)
	for i := range data {
		data[i] = generateA(r)
	}
	arena := make([]byte, 0, 512)
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		a := data[r.Intn(len(data))]
		msg, seg, _ := capnp.NewMessage(capnp.SingleSegment(arena[:0]))
		root, _ := air.NewRootBenchmarkA(seg)
		Insert(air.BenchmarkA_TypeID, root.Struct, a)
		msg.Marshal()
	}
}
Exemplo n.º 2
0
func BenchmarkExtract(b *testing.B) {
	r := rand.New(rand.NewSource(12345))
	data := make([][]byte, 1000)
	for i := range data {
		a := generateA(r)
		msg, seg, _ := capnp.NewMessage(capnp.SingleSegment(nil))
		root, _ := air.NewRootBenchmarkA(seg)
		Insert(air.BenchmarkA_TypeID, root.Struct, a)
		data[i], _ = msg.Marshal()
	}
	b.ReportAllocs()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		msg, _ := capnp.Unmarshal(data[r.Intn(len(data))])
		root, _ := msg.RootPtr()
		var a A
		Extract(&a, air.BenchmarkA_TypeID, root.Struct())
	}
}