-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarshaler_test.go
46 lines (39 loc) · 1.07 KB
/
marshaler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package cacheya
import (
"fmt"
"testing"
"time"
"github.com/kongxinchi/cacheya/marshaller"
)
type MarshallerTestObject struct {
ID int64
State string
QwExternalUserID string
UID string
ContactID *string
}
func TestMarshaller_Benchmark(t *testing.T) {
marshallerBenchmark("JSON", marshaller.NewJsonMarshaller())
marshallerBenchmark("MSGPACK", marshaller.NewMsgpackMarshaller())
}
func marshallerBenchmark(name string, marshaller Marshaller) {
contactID := "64b4dcf8-e0c9-11ee-8c00-dafebafdd11e"
o := &MarshallerTestObject{
ID: 258497503316467713,
State: "active",
QwExternalUserID: "wmJawBCQAA7R7dpI98pWhYWzWstkI86A",
UID: "6",
ContactID: &contactID,
}
begin := time.Now()
for i := 0; i < 10000; i++ {
_, _ = marshaller.Marshal(o)
}
fmt.Printf("%s Marshal: %s\n", name, time.Since(begin))
s, _ := marshaller.Marshal(o)
begin = time.Now()
for i := 0; i < 10000; i++ {
_ = marshaller.Unmarshal(s, o)
}
fmt.Printf("%s Unmarshal: %s\n", name, time.Since(begin))
}