Skip to content

Commit

Permalink
session: add benchmark for PointGet, BatchPointGet, prepared PointGet (
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Jul 7, 2021
1 parent 14adc46 commit 8b4aa3f
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions session/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/sqlexec"
"go.uber.org/zap"
Expand Down Expand Up @@ -252,6 +253,84 @@ func BenchmarkExplainStringIndexScan(b *testing.B) {
b.StopTimer()
}

func BenchmarkPointGet(b *testing.B) {
ctx := context.Background()
se, do, st := prepareBenchSession()
defer func() {
se.Close()
do.Close()
st.Close()
}()
mustExecute(se, "create table t (pk int primary key)")
mustExecute(se, "insert t values (61),(62),(63),(64)")
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where pk = 64")
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs[0])
if err != nil {
b.Fatal(err)
}
}
b.StopTimer()
}

func BenchmarkBatchPointGet(b *testing.B) {
ctx := context.Background()
se, do, st := prepareBenchSession()
defer func() {
se.Close()
do.Close()
st.Close()
}()
mustExecute(se, "create table t (pk int primary key)")
mustExecute(se, "insert t values (61),(62),(63),(64)")
b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.Execute(ctx, "select * from t where pk in (61, 64, 67)")
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs[0])
if err != nil {
b.Fatal(err)
}
}
b.StopTimer()
}

func BenchmarkPreparedPointGet(b *testing.B) {
ctx := context.Background()
se, do, st := prepareBenchSession()
defer func() {
se.Close()
do.Close()
st.Close()
}()
mustExecute(se, "create table t (pk int primary key)")
mustExecute(se, "insert t values (61),(62),(63),(64)")

stmtID, _, _, err := se.PrepareStmt("select * from t where pk = ?")
if err != nil {
b.Fatal(err)
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
rs, err := se.ExecutePreparedStmt(ctx, stmtID, []types.Datum{types.NewDatum(64)})
if err != nil {
b.Fatal(err)
}
_, err = drainRecordSet(ctx, se.(*session), rs)
if err != nil {
b.Fatal(err)
}
}
b.StopTimer()
}

func BenchmarkStringIndexLookup(b *testing.B) {
ctx := context.Background()
se, do, st := prepareBenchSession()
Expand Down Expand Up @@ -1643,6 +1722,9 @@ func TestBenchDaily(t *testing.T) {
}

tests := []func(b *testing.B){
BenchmarkPreparedPointGet,
BenchmarkPointGet,
BenchmarkBatchPointGet,
BenchmarkBasic,
BenchmarkTableScan,
BenchmarkTableLookup,
Expand Down

0 comments on commit 8b4aa3f

Please sign in to comment.