Esempio n. 1
0
func TestUnmarshalFaster(t *testing.T) {
	buf := []byte(`{"id": 123213, "OriginId": 22, "meth": "GET"}`)
	record := newLogFFRecord()
	err := ffjson.UnmarshalFast(buf, record)
	require.NoError(t, err)

	r2 := newLogRecord()
	err = ffjson.UnmarshalFast(buf, r2)
	require.Error(t, err, "Record should not support UnmarshalFast")
	err = ffjson.Unmarshal(buf, r2)
	require.NoError(t, err)
}
Esempio n. 2
0
func BenchmarkFF_Unmarshal_M(b *testing.B) {
	b.SetBytes(int64(len(largeStructText)))
	for i := 0; i < b.N; i++ {
		var s LargeStruct
		err := ffjson.UnmarshalFast(largeStructText, &s)
		if err != nil {
			b.Error(err)
		}
	}
}
Esempio n. 3
0
func BenchmarkFF_Unmarshal_S(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var s Entities
		err := ffjson.UnmarshalFast(smallStructText, &s)
		if err != nil {
			b.Error(err)
		}
	}
	b.SetBytes(int64(len(smallStructText)))
}
Esempio n. 4
0
func BenchmarkSXimpleUnmarshalNative(b *testing.B) {
	record := newLogRecord()
	buf := []byte(`{"id": 123213, "OriginId": 22, "meth": "GET"}`)
	err := json.Unmarshal(buf, record)
	if err != nil {
		b.Fatalf("json.Unmarshal: %v", err)
	}
	b.SetBytes(int64(len(buf)))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		err := ffjson.UnmarshalFast(buf, record)
		if err != nil {
			b.Fatalf("json.Unmarshal: %v", err)
		}
	}
}
Esempio n. 5
0
func (j *JsonDecoder) Decode(raw []byte, e *Event) error {
	err := ffjson.UnmarshalFast(raw, e)
	return err
}