From 2a68b737732b959365cf4e2abaee1eaf486f27e9 Mon Sep 17 00:00:00 2001 From: xing Date: Wed, 22 Feb 2023 19:05:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/query_test.go | 2 ++ model/querycondition_test.go | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/model/query_test.go b/model/query_test.go index a47482a..ee38a57 100644 --- a/model/query_test.go +++ b/model/query_test.go @@ -101,6 +101,7 @@ func (p post) Table() string { var ctx = context.Background() var glob *SqlxQuery +var ddb *sqlx.DB func init() { db, err := sqlx.Open("mysql", "root:root@tcp(192.168.66.47:3306)/wordpress?charset=utf8mb4&parseTime=True&loc=Local") @@ -108,6 +109,7 @@ func init() { panic(err) } glob = NewSqlxQuery(db, NewUniversalDb(nil, nil)) + ddb = db InitDB(glob) } func TestFind(t *testing.T) { diff --git a/model/querycondition_test.go b/model/querycondition_test.go index 142118f..93ef718 100644 --- a/model/querycondition_test.go +++ b/model/querycondition_test.go @@ -507,10 +507,21 @@ func Test_findScanner(t *testing.T) { } } +func BenchmarkSqlxQueryXX(b *testing.B) { + for i := 0; i < b.N; i++ { + var r []options + err := ddb.Select(&r, "select * from wp_options where option_id<100") + if err != nil { + panic(err) + } + } +} + func BenchmarkScannerXX(b *testing.B) { for i := 0; i < b.N; i++ { + var r []options err := findScanner[options](glob, ctx, func(t options) { - _ = t + r = append(r, t) //fmt.Println(t) }, Conditions(Where(SqlBuilder{{"option_id", "<", "100", "int"}}))) if err != nil { @@ -521,14 +532,10 @@ func BenchmarkScannerXX(b *testing.B) { func BenchmarkFindsXX(b *testing.B) { for i := 0; i < b.N; i++ { - r, err := finds[options](glob, ctx, Conditions(Where(SqlBuilder{{"option_id", "<", "100", "int"}}))) + _, err := finds[options](glob, ctx, Conditions(Where(SqlBuilder{{"option_id", "<", "100", "int"}}))) if err != nil { panic(err) } - for _, o := range r { - _ = o - //fmt.Println(o) - } } }