-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparison_test.go
75 lines (64 loc) · 1.3 KB
/
comparison_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//go:build cbor_comparison
package cbor
import (
"bytes"
"fmt"
"io"
"testing"
fxcbor "github.com/fxamacker/cbor/v2"
"github.com/google/go-cmp/cmp"
)
func Test_ReadAny_Comparison(t *testing.T) {
for _, tt := range tests_ExampleEncoded {
t.Run(tt.encoded, func(t *testing.T) {
encoded := decodeHex(t, tt.encoded)
in := bytes.NewReader(encoded)
var err error
var out any
var outFx any
{
in.Seek(0, io.SeekStart)
out, err = ReadAny(in)
if err != nil {
t.Fatal(err)
}
}
{
in.Seek(0, io.SeekStart)
err = fxcbor.Unmarshal(encoded, &outFx)
if err != nil {
t.Fatal(err)
}
}
if diff := cmp.Diff(out, outFx); diff != "" {
t.Fatal(diff)
}
})
}
}
func Benchmark_ReadAny_Comparison(b *testing.B) {
for _, tt := range tests_ExampleEncoded {
encoded := decodeHex(b, tt.encoded)
in := bytes.NewReader(encoded)
var out any
var err error
b.Run(fmt.Sprintf("%s", tt.encoded), func(b *testing.B) {
for range b.N {
in.Seek(0, io.SeekStart)
out, err = ReadAny(in)
if err != nil {
b.Fatal(err)
}
}
})
b.Run(fmt.Sprintf("fx %s", tt.encoded), func(b *testing.B) {
for range b.N {
in.Seek(0, io.SeekStart)
err = fxcbor.Unmarshal(encoded, &out)
if err != nil {
b.Fatal(err)
}
}
})
}
}