Created
June 9, 2020 18:46
-
-
Save kyanny/57c3c7aeaa451e1513442b97c1cef955 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
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func pp(a []uint64, oldcap int) { | |
if cap(a) != oldcap { | |
var ntimes float64 | |
if oldcap != 0 { | |
ntimes = float64(cap(a))/float64(oldcap) | |
} | |
fmt.Printf("len=%d, cap=%d, ntimes=%f\n", len(a), cap(a), ntimes) | |
} | |
} | |
func main() { | |
a := make([]uint64, 0) | |
oldcap := cap(a) | |
pp(a, oldcap) | |
var i uint64 | |
for i = 0; i < uint64(math.Pow(2, 32)); i++ { | |
oldcap := cap(a) | |
a = append(a, 0) | |
pp(a, oldcap) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment