This commit is contained in:
xing 2023-02-22 19:05:47 +08:00
parent f885b5c8f0
commit 2a68b73773
2 changed files with 15 additions and 6 deletions

View File

@ -101,6 +101,7 @@ func (p post) Table() string {
var ctx = context.Background() var ctx = context.Background()
var glob *SqlxQuery var glob *SqlxQuery
var ddb *sqlx.DB
func init() { func init() {
db, err := sqlx.Open("mysql", "root:root@tcp(192.168.66.47:3306)/wordpress?charset=utf8mb4&parseTime=True&loc=Local") 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) panic(err)
} }
glob = NewSqlxQuery(db, NewUniversalDb(nil, nil)) glob = NewSqlxQuery(db, NewUniversalDb(nil, nil))
ddb = db
InitDB(glob) InitDB(glob)
} }
func TestFind(t *testing.T) { func TestFind(t *testing.T) {

View File

@ -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) { func BenchmarkScannerXX(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
var r []options
err := findScanner[options](glob, ctx, func(t options) { err := findScanner[options](glob, ctx, func(t options) {
_ = t r = append(r, t)
//fmt.Println(t) //fmt.Println(t)
}, Conditions(Where(SqlBuilder{{"option_id", "<", "100", "int"}}))) }, Conditions(Where(SqlBuilder{{"option_id", "<", "100", "int"}})))
if err != nil { if err != nil {
@ -521,14 +532,10 @@ func BenchmarkScannerXX(b *testing.B) {
func BenchmarkFindsXX(b *testing.B) { func BenchmarkFindsXX(b *testing.B) {
for i := 0; i < b.N; i++ { 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 { if err != nil {
panic(err) panic(err)
} }
for _, o := range r {
_ = o
//fmt.Println(o)
}
} }
} }