mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
update
This commit is contained in:
39
tests/string_test.go
Normal file
39
tests/string_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkStringSplice(b *testing.B) {
|
||||
userID := "aaaaa"
|
||||
orderID := "bbccc"
|
||||
|
||||
b.Run("BenchmarkPlus", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
logStr := "userid :" + userID + "; orderid:" + orderID
|
||||
_ = logStr
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("BenchmarkPrint", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
logStr := fmt.Sprintf("userid: %v; orderid: %v", userID, orderID)
|
||||
_ = logStr
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("BenchmarkBytesBuffer", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var sb bytes.Buffer
|
||||
sb.WriteString("userid :")
|
||||
sb.WriteString(userID)
|
||||
sb.WriteString("; orderid:")
|
||||
sb.WriteString(orderID)
|
||||
|
||||
logStr := sb.String()
|
||||
_ = logStr
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user