Skip to content

Instantly share code, notes, and snippets.

@hslr4
Created February 26, 2019 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hslr4/4b069e609e6a6904685e8912a6b98c02 to your computer and use it in GitHub Desktop.
Save hslr4/4b069e609e6a6904685e8912a6b98c02 to your computer and use it in GitHub Desktop.
func main() {
times := 1000
results := make([]time.Duration, 0, times)
for t := 0; t < times; t++ {
start := time.Now()
// initialize either with capacity of 0
// test := make([]int, 0)
// or initialize with final capacity of 100
test := make([]int, 0, 100)
for i := 0; i < 100; i++ {
// uncomment to see how the capacity grows in larger steps
// fmt.Println(cap(test), len(test))
test = append(test, i)
}
elapsed := time.Now().Sub(start)
results = append(results, elapsed)
}
printSummary(results)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment