Created
May 24, 2017 13:59
-
-
Save vaskoz/b7784831f22aef798c6df318b576acfe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
go test -bench=. itoa_test.go | |
goos: darwin | |
goarch: amd64 | |
BenchmarkFmtSprintf-4 2000000 938 ns/op | |
BenchmarkStrconvItoa-4 5000000 253 ns/op | |
PASS | |
ok command-line-arguments 4.335s |
This file contains hidden or 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 | |
import ( | |
"fmt" | |
"strconv" | |
"testing" | |
) | |
var testcases = []int{123, 9, 987654321, 101, 512, 22223333} | |
func BenchmarkFmtSprintf(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
for _, val := range testcases { | |
fmt.Sprintf("%d", val) | |
} | |
} | |
} | |
func BenchmarkStrconvItoa(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
for _, val := range testcases { | |
strconv.Itoa(val) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment