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

	buf, err := json.Marshal(&cust)
	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(&cust)
		if err != nil {
			b.Fatalf("Marshal: %v", err)
		}
	}
}