Merge pull request #17 from tsenart/master

Use encoding/hex pkg for generating UID strings
This commit is contained in:
Naren Venkataraman 2013-10-11 13:06:40 -07:00
commit 6c98fad211
2 changed files with 23 additions and 2 deletions

View File

@ -2,7 +2,7 @@ package http
import ( import (
"crypto/rand" "crypto/rand"
"fmt" "encoding/hex"
"io" "io"
) )
@ -20,5 +20,5 @@ func uid() string {
panic(err) panic(err)
} }
return fmt.Sprintf("%x", id) return hex.EncodeToString(id)
} }

21
src/http/uid_test.go Normal file
View File

@ -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)
}
}