-
-
Save hslr4/4b069e609e6a6904685e8912a6b98c02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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