Created
November 22, 2023 09:39
-
-
Save yumed15/5f78bcef6ff173a27ffe8264fbee38c6 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
type T struct { | |
X [1000]int32 // 4KB | |
} | |
var global interface{} | |
func BenchmarkAllocOnHeap(b *testing.B) { | |
b.ReportAllocs() | |
for i := 0; i <= b.N; i++ { | |
global = &T{} | |
} | |
} | |
func BenchmarkAllocOnStack(b *testing.B) { | |
b.ReportAllocs() | |
for i := 0; i <= b.N; i++ { | |
local := T{} | |
_ = local | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment