Exemplo 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)
}
Exemplo 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)
		}
	}
}
Exemplo 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)))
}
Exemplo 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)
		}
	}
}
Exemplo n.º 5
0
func (j *JsonDecoder) Decode(raw []byte, e *Event) error {
	err := ffjson.UnmarshalFast(raw, e)
	return err
}