From 2aacb682e158c62778c91947e152ba5f9d989dad Mon Sep 17 00:00:00 2001 From: xing Date: Wed, 22 Feb 2023 20:59:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E4=BC=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/strings/strings_test.go | 31 +++++++++++++++++++++++++++++++ model/parse.go | 5 +++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/helper/strings/strings_test.go b/helper/strings/strings_test.go index 33f75f8..5531bf2 100644 --- a/helper/strings/strings_test.go +++ b/helper/strings/strings_test.go @@ -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() + } +} diff --git a/model/parse.go b/model/parse.go index caef825..74dae43 100644 --- a/model/parse.go +++ b/model/parse.go @@ -1,7 +1,6 @@ package model import ( - "fmt" "github.com/fthvgb1/wp-go/helper/slice" "strconv" "strings" @@ -108,7 +107,9 @@ func (w SqlBuilder) ParseWhere(in *[][]any) (string, []any, error) { st = strings.TrimRight(st, "and ") s.Reset() s.WriteString(st) - s.WriteString(fmt.Sprintf(" %s ", ss[start])) + s.WriteString(" ") + s.WriteString(ss[start]) + s.WriteString(" ") } if i == 0 { s.WriteString("( ")