Skip to content

Instantly share code, notes, and snippets.

@ardan-bkennedy
Created August 21, 2014 13:11
Show Gist options
  • Save ardan-bkennedy/6ffc995f65d0ff5ee88c to your computer and use it in GitHub Desktop.
Save ardan-bkennedy/6ffc995f65d0ff5ee88c to your computer and use it in GitHub Desktop.
Go Allocation Challenge
// Created by Bill Hathaway to see if line 16 would produce an
// allocation in Go v1.3
package main
import (
"testing"
)
var (
m = make(map[string]struct{})
ba = []byte{104, 101, 108, 108, 111}
)
func BenchmarkExternalAllocations(b *testing.B) {
for i := 0; i < b.N; i++ {
external := string(ba)
m[external] = struct{}{}
}
b.ReportAllocs()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment