Created
May 9, 2020 12:18
-
-
Save andrewslotin/b43e9c9cb4863335ed48894c5b731a91 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_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