Skip to content

Instantly share code, notes, and snippets.

@renanbastos93
Created January 10, 2022 10:05
Show Gist options
  • Save renanbastos93/54cca591d2d30beaa5b30cd89106cf3d to your computer and use it in GitHub Desktop.
Save renanbastos93/54cca591d2d30beaa5b30cd89106cf3d to your computer and use it in GitHub Desktop.
package main
var size = 10000
func useAppendWithoutLength() {
var arr = []int{}
for i := 0; i < size; i++ {
arr = append(arr, i)
}
}
func useAppendWithLength() {
var arr = make([]int, 0, size)
for i := 0; i < size; i++ {
arr = append(arr, i)
}
}
func notUseAppend() {
var arr = make([]int, 1, size)
for k := range arr {
arr[k] = k
}
}
func main() {
useAppendWithLength()
useAppendWithoutLength()
notUseAppend()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment