Skip to content

Instantly share code, notes, and snippets.

@andrewslotin
Created May 9, 2020 12:18
Show Gist options
  • Save andrewslotin/b43e9c9cb4863335ed48894c5b731a91 to your computer and use it in GitHub Desktop.
Save andrewslotin/b43e9c9cb4863335ed48894c5b731a91 to your computer and use it in GitHub Desktop.
package main_test
import (
"runtime"
"testing"
)
//go:noinline
func switchImplementation() int {
switch runtime.GOARCH {
case "amd64":
return 0
case "arm64":
return 1
case "arm":
return 2
default:
return 0
}
}
func BenchmarkSwitchImpl(b *testing.B) {
for i := 0; i < b.N; i++ {
switchImplementation()
}
}
var m = map[string]int{
"amd64": 0,
"arm": 1,
"arm64": 2,
}
func mapImplementation() int {
return m[runtime.GOARCH]
}
func BenchmarkMapImpl(b *testing.B) {
for i := 0; i < b.N; i++ {
mapImplementation()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment