-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcopy_test.go
More file actions
95 lines (87 loc) · 1.81 KB
/
copy_test.go
File metadata and controls
95 lines (87 loc) · 1.81 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* File: copy.go
* Created Date: 2022-01-26 05:36:00
* Author: ysj
* Description: copy slice and map by type; copy struct by field name
*/
package gocopy
import (
"testing"
"time"
"github.com/jinzhu/copier"
)
type Perm1 struct {
Action string
Label string
}
type Perm2 struct {
anonymous1 string
anonymous2 int
Action string
Label string
}
type EmbedFields struct {
EmbedF1 string
embedF2 string
}
type AccessRolePerms1 struct {
Role string
Roll *int
Actions []string
Perms []*Perm1
PermMap map[string]*Perm1
From string
EmbedFields
CreatedAt time.Time
UpdatedAt string
Child *AccessRolePerms1
}
type AccessRolePerms2 struct {
Role *string
Roll *int
Actions []string
Perms []*Perm2
PermMap map[string]*Perm2
To []byte
EmbedF1 string
CreatedAt string
UpdatedAt time.Time
Child *AccessRolePerms2
}
func BenchmarkCopy(b *testing.B) {
roll := 100
from := AccessRolePerms1{
Role: "角色",
Roll: &roll,
EmbedFields: EmbedFields{
EmbedF1: "embedF1",
},
Actions: []string{"xxx", "yyy"},
Perms: []*Perm1{{Action: "GET", Label: "rest-get-method"}},
PermMap: map[string]*Perm1{"perm": {Action: "PUT", Label: "rest-put-method"}},
}
to := AccessRolePerms2{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
Copy(&to, from)
}
}
func BenchmarkCopier(b *testing.B) {
roll := 100
from := AccessRolePerms1{
Role: "角色",
Roll: &roll,
EmbedFields: EmbedFields{
EmbedF1: "embedF1",
},
Actions: []string{"xxx", "yyy"},
Perms: []*Perm1{{Action: "GET", Label: "rest-get-method"}},
PermMap: map[string]*Perm1{"perm": {Action: "PUT", Label: "rest-put-method"}},
}
to := AccessRolePerms2{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
copier.Copy(&to, from)
// copier.CopyWithOption(&to, from, copier.Option{DeepCopy: true})
}
}