diff --git a/src/http/uid.go b/src/http/uid.go index da3a468..45e5898 100644 --- a/src/http/uid.go +++ b/src/http/uid.go @@ -2,7 +2,7 @@ package http import ( "crypto/rand" - "fmt" + "encoding/hex" "io" ) @@ -20,5 +20,5 @@ func uid() string { panic(err) } - return fmt.Sprintf("%x", id) + return hex.EncodeToString(id) } diff --git a/src/http/uid_test.go b/src/http/uid_test.go new file mode 100644 index 0000000..3fa2061 --- /dev/null +++ b/src/http/uid_test.go @@ -0,0 +1,21 @@ +package http + +import ( + "encoding/hex" + "fmt" + "testing" +) + +func BenchmarkFmtString(b *testing.B) { + id := []byte("1234567891234567") + for i := 0; i < b.N; i++ { + fmt.Sprintf("%x", id) + } +} + +func BenchmarkHexString(b *testing.B) { + id := []byte("1234567891234567") + for i := 0; i < b.N; i++ { + hex.EncodeToString(id) + } +}