Last active
September 18, 2019 20:20
-
-
Save blanchonvincent/dfa2ecd831080488afdd8893423de728 to your computer and use it in GitHub Desktop.
Medium - Garbage Collector
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 BenchmarkAllocationEveryMs(b *testing.B) { | |
// need permanent allocation to clear see when the heap double its size | |
var s *[]int | |
tmp := make([]int, 1100000, 1100000) | |
s = &tmp | |
var a *[]int | |
for i := 0; i < b.N; i++ { | |
tmp := make([]int, 10000, 10000) | |
a = &tmp | |
time.Sleep(time.Millisecond) | |
} | |
_ = a | |
runtime.KeepAlive(s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment