Skip to content

Instantly share code, notes, and snippets.

@vaskoz
Created May 24, 2017 13:59
Show Gist options
  • Save vaskoz/b7784831f22aef798c6df318b576acfe to your computer and use it in GitHub Desktop.
Save vaskoz/b7784831f22aef798c6df318b576acfe to your computer and use it in GitHub Desktop.
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
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