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

Function MakeSliceWithoutAlloc

source/gotest/benchmark.go:4–12  ·  view source on GitHub ↗

MakeSliceWithPreAlloc 不预分配

()

Source from the content-addressed store, hash-verified

2
3// MakeSliceWithPreAlloc 不预分配
4func MakeSliceWithoutAlloc() []int {
5 var newSlice []int
6
7 for i := 0; i < 100000; i++ {
8 newSlice = append(newSlice, i)
9 }
10
11 return newSlice
12}
13
14// MakeSliceWithPreAlloc 通过预分配Slice的存储空间构造
15func MakeSliceWithPreAlloc() []int {

Callers 4

benchSub1Function · 0.92
benchSub2Function · 0.92
benchSub3Function · 0.92

Calls

no outgoing calls

Tested by 4

benchSub1Function · 0.74
benchSub2Function · 0.74
benchSub3Function · 0.74