Skip to content

Commit b386f44

Browse files
committed
Update slice_test.go
1 parent 3ec840c commit b386f44

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 .

examples/singleapp/slice_performance_tips/slice_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

1921
func 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

2933
func 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
}

0 commit comments

Comments
 (0)