File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
examples/singleapp/slice_performance_tips Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 1+ version : ' 3'
2+
3+ tasks :
4+ default :
5+ cmds :
6+ - task : bench
7+ - task : bench
8+ - task : bench
9+ bench :
10+ cmds :
11+ - go test -bench .
Original file line number Diff line number Diff line change @@ -10,29 +10,35 @@ func BenchmarkSliceLen0Append(b *testing.B) {
1010 s []string
1111 )
1212
13+ b .StartTimer ()
1314 for i := 0 ; i < b .N ; i ++ {
1415 //lint:ignore SA4010 ok
1516 s = append (s , strconv .Itoa (i ))
1617 }
18+ b .StopTimer ()
1719}
1820
1921func BenchmarkSliceLenN (b * testing.B ) {
2022 var (
2123 s = make ([]string , b .N )
2224 )
2325
26+ b .StartTimer ()
2427 for i := 0 ; i < b .N ; i ++ {
2528 s [i ] = strconv .Itoa (i )
2629 }
30+ b .StopTimer ()
2731}
2832
2933func BenchmarkSliceLenNAppend (b * testing.B ) {
3034 var (
3135 s = make ([]string , 0 , b .N )
3236 )
3337
38+ b .StartTimer ()
3439 for i := 0 ; i < b .N ; i ++ {
3540 //lint:ignore SA4010 ok
3641 s = append (s , strconv .Itoa (i ))
3742 }
43+ b .StopTimer ()
3844}
You can’t perform that action at this time.
0 commit comments