-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreflect_test.go
65 lines (51 loc) · 1.11 KB
/
reflect_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
package utils
import (
"encoding/json"
"fmt"
"golang.org/x/tools/container/intsets"
"reflect"
"testing"
"time"
"unsafe"
)
func TestStructSetFieldValue(t *testing.T) {
type E struct{ N string }
e1 := E{N: "222"}
StructSetFieldValue(&e1, "N", "fff")
fmt.Println(e1)
}
func TestInterfaceToInt(t *testing.T) {
start := time.Now()
for i:=0;i<100000000;i++{
// v := BasicTypeToInt64(i)
_ = *(*int32)(unsafe.Pointer(&i))
}
middle := time.Now()
// for i:=0;i<100000000;i++{
//// v := BasicTypeToInt64(i)
// _ = int32(i)
// }
// middle := time.Now()
//fmt.Println(end.UnixNano() - middle.UnixNano())
fmt.Println(middle.UnixNano() - start.UnixNano())
}
func TestMaxIntToInt(t *testing.T) {
i := int64(intsets.MaxInt)
fmt.Println(i)
fmt.Println(int32(i))
fmt.Println(*(*int32)(unsafe.Pointer(&i)))
}
func TestUnmarshalNumber(t *testing.T) {
type Num struct {
I int64 `json:"i"`
}
n := map[string]interface{}{
"i":8102055647965417472,
}
//n := &Num{I:8102055647965417472}
v,_ := json.Marshal(n)
n1 := &Num{}
UnmarshalNumber(v, n1)
fmt.Println(reflect.TypeOf(n1.I).String())
fmt.Println(n1.I)
}