예제 #1
0
func getBaseData(b fatalF) []byte {
	var record base.Log
	base.NewLog(&record)
	buf, err := json.MarshalIndent(&record, "", "    ")
	if err != nil {
		b.Fatalf("Marshal: %v", err)
	}
	return buf
}
예제 #2
0
func BenchmarkMarshalJSON(b *testing.B) {
	var record base.Log
	base.NewLog(&record)

	buf, err := json.Marshal(&record)
	if err != nil {
		b.Fatalf("Marshal: %v", err)
	}
	b.SetBytes(int64(len(buf)))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, err := json.Marshal(&record)
		if err != nil {
			b.Fatalf("Marshal: %v", err)
		}
	}
}