-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark1_test.go
53 lines (49 loc) · 1.11 KB
/
benchmark1_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
package test
import (
"testing"
"github.com/farseer-go/mapper"
)
type SamplePO struct {
UserName string
IsEnable bool
Id int
Id8 int8
Id16 int16
Id32 int32
Id64 int64
IdUint uint
IdUint8 uint8
IdUint16 uint16
IdUint32 uint32
IdUint64 uint64
IdFloat32 float32
IdFloat64 float64
}
// BenchmarkCopyStruct-12 14 81,855216 ns/op 12800284 B/op 610000 allocs/op (jinzhu)
// BenchmarkSample1-12 28 39,790300 ns/op 39680051 B/op 100000 allocs/op
// BenchmarkSample1-10 61 18,903289 ns/op 39680284 B/op 100001 allocs/op
// BenchmarkSample1-10 64 18,751998 ns/op 38000186 B/op 370001 allocs/op
func BenchmarkSample1(b *testing.B) {
po := SamplePO{
UserName: "UserName",
IsEnable: true,
Id: 1,
Id8: 8,
Id16: 16,
Id32: 32,
Id64: 64,
IdUint: 1,
IdUint8: 8,
IdUint16: 16,
IdUint32: 32,
IdUint64: 64,
IdFloat32: 32.32,
IdFloat64: 64.64,
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for i := 0; i < 10000; i++ {
mapper.Single[SamplePO](po)
}
}
}