示例#1
0
文件: bench_test.go 项目: rw/goser
func BenchmarkUnmarshalCapnp(b *testing.B) {
	segment := capn.NewBuffer(make([]byte, 0, 1<<20))
	record := capnp.NewRootLog(segment)
	newCapnpLog(&record)

	var buf bytes.Buffer
	_, err := segment.WriteTo(&buf)
	if err != nil {
		b.Fatalf("WriteTo: %v", err)
	}
	b.SetBytes(int64(len(buf.Bytes())))

	segmentBuf := bytes.NewBuffer(make([]byte, 0, 1<<20))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		r := bytes.NewBuffer(buf.Bytes())
		seg, err := capn.ReadFromStream(r, segmentBuf)
		if err != nil {
			b.Fatalf("ReadFromStream: %v", err)
		}
		record := capnp.ReadRootLog(seg)
		_ = record
	}
}
示例#2
0
文件: bench_test.go 项目: rw/goser
func BenchmarkPopulateCapnp(b *testing.B) {
	buf := make([]byte, 1<<20)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		segment := capn.NewBuffer(buf[:0])
		record := capnp.NewRootLog(segment)
		newCapnpLog(&record)
	}
}
示例#3
0
文件: bench_test.go 项目: rw/goser
func BenchmarkMarshalCapnp(b *testing.B) {
	segment := capn.NewBuffer(make([]byte, 0, 1<<20))
	record := capnp.NewRootLog(segment)
	newCapnpLog(&record)

	var buf bytes.Buffer
	_, err := segment.WriteTo(&buf)
	if err != nil {
		b.Fatalf("WriteTo: %v", err)
	}
	b.SetBytes(int64(len(buf.Bytes())))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		buf.Reset()
		_, err := segment.WriteTo(&buf)
		if err != nil {
			b.Fatalf("WriteTo: %v", err)
		}
	}
}