MCPcopy
hub / github.com/RainbowMango/GoExpertProgramming / MakeSliceWithPreAlloc

Function MakeSliceWithPreAlloc

source/gotest/benchmark.go:15–24  ·  view source on GitHub ↗

MakeSliceWithPreAlloc 通过预分配Slice的存储空间构造

()

Source from the content-addressed store, hash-verified

13
14// MakeSliceWithPreAlloc 通过预分配Slice的存储空间构造
15func MakeSliceWithPreAlloc() []int {
16 var newSlice []int
17
18 newSlice = make([]int, 0, 100000)
19 for i := 0; i < 100000; i++ {
20 newSlice = append(newSlice, i)
21 }
22
23 return newSlice
24}

Callers 1

Calls

no outgoing calls

Tested by 1