Created
November 20, 2023 17:44
-
-
Save yarysh/2669426e755e2d83059438aa08d8e19b to your computer and use it in GitHub Desktop.
Revisions
-
yarysh created this gist
Nov 20, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ package main import "fmt" func main() { initLen, insertions := 64, 1024*10 s := make([]int, 0, initLen) currCap := cap(s) for i := 0; i < insertions; i++ { s = append(s, i) if currCap < cap(s) { fmt.Printf( "Capacity was increased from %d to %d (%.2f%%)\n", currCap, cap(s), (1-float64(currCap)/float64(cap(s)))*100, ) currCap = cap(s) } } }