-
-
Notifications
You must be signed in to change notification settings - Fork 489
/
copier_benchmark_test.go
56 lines (48 loc) · 1.6 KB
/
copier_benchmark_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
package copier_test
import (
"encoding/json"
"testing"
"github.com/jinzhu/copier"
)
func BenchmarkCopyStruct(b *testing.B) {
var fakeAge int32 = 12
user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}}
for x := 0; x < b.N; x++ {
copier.Copy(&Employee{}, &user)
}
}
func BenchmarkCopyStructFields(b *testing.B) {
var fakeAge int32 = 12
user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}}
for x := 0; x < b.N; x++ {
copier.Copy(&Employee{}, &user)
}
}
func BenchmarkNamaCopy(b *testing.B) {
var fakeAge int32 = 12
user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}}
for x := 0; x < b.N; x++ {
employee := &Employee{
Name: user.Name,
NickName: &user.Nickname,
Age: int64(user.Age),
FakeAge: int(*user.FakeAge),
DoubleAge: user.DoubleAge(),
}
for _, note := range user.Notes {
employee.Notes = append(employee.Notes, ¬e)
}
employee.Role(user.Role)
}
}
func BenchmarkJsonMarshalCopy(b *testing.B) {
var fakeAge int32 = 12
user := User{Name: "Jinzhu", Nickname: "jinzhu", Age: 18, FakeAge: &fakeAge, Role: "Admin", Notes: []string{"hello world", "welcome"}, flags: []byte{'x'}}
for x := 0; x < b.N; x++ {
data, _ := json.Marshal(user)
var employee Employee
json.Unmarshal(data, &employee)
employee.DoubleAge = user.DoubleAge()
employee.Role(user.Role)
}
}