func testTime() { loopNum := 100000*10000 go func(loopNum int) { arr := [size]int{1,2,3,4,5} for i:=0;i<len(arr);i++{ arr[i]=i } tOld := time.Now() for i:=0;i<loopNum;i++{ value := arr[i%size] if false{ fmt.Printf("%d,%d\n",loopNum,value) } } tNew := time.Now() tMin := tNew.Minute()-tOld.Minute() tSed := tNew.Second()-tOld.Second() tSed = tMin*60+tSed fmt.Printf("test arr size:%d cost time:%d\n",len(arr),tSed*1000*1000*1000+tNew.Nanosecond()-tOld.Nanosecond()) }(loopNum) go func(loopNum int) { arr := [size]int{1,2,3,4,5} for i:=0;i<size;i++{ arr[i]=i } slice := arr[:] tOld := time.Now() for i:=0;i<loopNum;i++{ value := slice[i%size] if false{ fmt.Printf("%d,%d\n",loopNum,value) } } tNew := time.Now() tMin := tNew.Minute()-tOld.Minute() tSed := tNew.Second()-tOld.Second() tSed = tMin*60+tSed fmt.Printf("test slice size:%d cost time:%d\n",len(slice),tSed*1000*1000*1000+tNew.Nanosecond()-tOld.Nanosecond()) }(loopNum) go func(loopNum int) { map2 := make(map[int]int) for i:=0;i<size;i++{ map2[i]=i } tOld := time.Now() for i:=0;i<loopNum;i++{ value := map2[i%size] if false{ fmt.Printf("%d,%d\n",loopNum,value) } } tNew := time.Now() tMin := tNew.Minute()-tOld.Minute() tSed := tNew.Second()-tOld.Second() tSed = tMin*60+tSed fmt.Printf("test map2 size:%d cost time:%d\n",len(map2),tSed*1000*1000*1000+tNew.Nanosecond()-tOld.Nanosecond()) }(loopNum) }
size=10
test arr size:10 cost time:1281287900
test slice size:10 cost time:1282287900
test map2 size:10 cost time:9804217200
size=100
test slice size:100 cost time:1233275300
test arr size:100 cost time:1236276000
test map2 size:100 cost time:16125632500
size=1000
test arr size:1000 cost time:1131253000
test slice size:1000 cost time:1140255100
test map2 size:1000 cost time:20600644200
size = 10000
test slice size:10000 cost time:1120241600
test arr size:10000 cost time:1133255100
test map2 size:10000 cost time:25400722700
size = 10*10000
test slice size:100000 cost time:1143812300
test arr size:100000 cost time:1143812300
test map2 size:100000 cost time:30350851200
size = 100*10000
test slice size:1000000 cost time:1126461400
test arr size:1000000 cost time:1126461400
test map2 size:1000000 cost time:72473326100
size = 1000*10000
test slice size:10000000 cost time:1251294200
test arr size:10000000 cost time:1262296900
test map2 size:10000000 cost time:86622657300
size = 5000*10000
test arr size:50000000 cost time:1238287400
test slice size:50000000 cost time:1235287400
test map2 size:50000000 cost time:106376998500