Golang??????????????
???????????? ???????[ 2016/8/29 11:01:45 ] ???????????????? ???????
????????????
?????????Golang????????????? ????????????????y??з????native?????????
package main
import (
"reflect"
"testing"
)
type data struct {
Hp int
}
const AssignTimes = 100000000
func TestNativeAssign(t *testing.T) {
v := data{Hp: 2}
for i := 0; i < AssignTimes; i++ {
v.Hp = 3
}
}
func TestReflectAssign(t *testing.T) {
v := data{Hp: 2}
vv := reflect.ValueOf(&v).Elem()
f := vv.FieldByName("Hp")
for i := 0; i < AssignTimes; i++ {
f.SetInt(3)
}
}
func TestReflectFindFieldAndAssign(t *testing.T) {
v := data{Hp: 2}
vv := reflect.ValueOf(&v).Elem()
for i := 0; i < AssignTimes; i++ {
vv.FieldByName("Hp").SetInt(3)
}
}
func foo(v int) {
}
const CallTimes = 100000000
func TestNativeCall(t *testing.T) {
for i := 0; i < CallTimes; i++ {
foo(i)
}
}
func TestReflectCall(t *testing.T) {
v := reflect.ValueOf(foo)
for i := 0; i < CallTimes; i++ {
v.Call([]reflect.Value{reflect.ValueOf(2)})
}
}
???????????????
=== RUN TestNativeAssign
— PASS: TestNativeAssign (0.03s)
=== RUN TestReflectAssign
— PASS: TestReflectAssign (0.41s)
=== RUN TestReflectFindFieldAndAssign
— PASS: TestReflectFindFieldAndAssign (9.86s)
=== RUN TestNativeCall
— PASS: TestNativeCall (0.03s)
=== RUN TestReflectCall
— PASS: TestReflectCall (21.46s)
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11