Merge pull request #17 from tsenart/master
Use encoding/hex pkg for generating UID strings
This commit is contained in:
commit
6c98fad211
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue