Skip to content

Instantly share code, notes, and snippets.

@yarysh
Created November 20, 2023 17:44
Show Gist options
  • Select an option

  • Save yarysh/2669426e755e2d83059438aa08d8e19b to your computer and use it in GitHub Desktop.

Select an option

Save yarysh/2669426e755e2d83059438aa08d8e19b to your computer and use it in GitHub Desktop.

Revisions

  1. yarysh created this gist Nov 20, 2023.
    22 changes: 22 additions & 0 deletions main.go
    Original 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)
    }
    }
    }