This commit is contained in:
xing 2023-02-22 20:59:26 +08:00
parent 2a68b73773
commit 2aacb682e1
2 changed files with 34 additions and 2 deletions

View File

@ -95,3 +95,34 @@ func TestBuilder_WriteString(t *testing.T) {
}) })
} }
} }
func BenchmarkBuilder_SprintfXX(b *testing.B) {
s := NewBuilder()
for i := 0; i < b.N; i++ {
s.Sprintf("%s %s %s", "a", "b", "c")
_ = s.String()
}
}
func BenchmarkSPrintfXX(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fmt.Sprintf("%s %s %s", "a", "b", "c")
}
}
func BenchmarkStrJoinXX(b *testing.B) {
s := strings.Builder{}
for i := 0; i < b.N; i++ {
s.WriteString("a ")
s.WriteString("b ")
s.WriteString("c ")
_ = s.String()
}
}
func BenchmarkBuilderJoinXX(b *testing.B) {
s := NewBuilder()
for i := 0; i < b.N; i++ {
s.WriteString("a ", "b ", "c")
_ = s.String()
}
}

View File

@ -1,7 +1,6 @@
package model package model
import ( import (
"fmt"
"github.com/fthvgb1/wp-go/helper/slice" "github.com/fthvgb1/wp-go/helper/slice"
"strconv" "strconv"
"strings" "strings"
@ -108,7 +107,9 @@ func (w SqlBuilder) ParseWhere(in *[][]any) (string, []any, error) {
st = strings.TrimRight(st, "and ") st = strings.TrimRight(st, "and ")
s.Reset() s.Reset()
s.WriteString(st) s.WriteString(st)
s.WriteString(fmt.Sprintf(" %s ", ss[start])) s.WriteString(" ")
s.WriteString(ss[start])
s.WriteString(" ")
} }
if i == 0 { if i == 0 {
s.WriteString("( ") s.WriteString("( ")