diff --git a/Makefile b/Makefile index 2bd37eb88c29c..9c3ad87f272fa 100644 --- a/Makefile +++ b/Makefile @@ -277,13 +277,14 @@ endif # Usage: # make bench-daily TO=/path/to/file.json bench-daily: - go test github.com/pingcap/tidb/session -run TestBenchDaily --outfile bench_daily.json - go test github.com/pingcap/tidb/executor -run TestBenchDaily --outfile bench_daily.json - go test github.com/pingcap/tidb/tablecodec -run TestBenchDaily --outfile bench_daily.json - go test github.com/pingcap/tidb/expression -run TestBenchDaily --outfile bench_daily.json - go test github.com/pingcap/tidb/util/rowcodec -run TestBenchDaily --outfile bench_daily.json - go test github.com/pingcap/tidb/util/codec -run TestBenchDaily --outfile bench_daily.json - go test github.com/pingcap/tidb/util/benchdaily -run TestBenchDaily \ + go test github.com/pingcap/tidb/session -bench BenchmarkDaily --outfile bench_daily.json + go test github.com/pingcap/tidb/executor -bench BenchmarkDaily --outfile bench_daily.json + go test github.com/pingcap/tidb/tablecodec -bench BenchmarkDaily --outfile bench_daily.json + go test github.com/pingcap/tidb/expression -bench BenchmarkDaily --outfile bench_daily.json + go test github.com/pingcap/tidb/util/rowcodec -bench BenchmarkDaily --outfile bench_daily.json + go test github.com/pingcap/tidb/util/codec -bench BenchmarkDaily --outfile bench_daily.json + go test github.com/pingcap/tidb/distsql -bench BenchmarkDaily --outfile bench_daily.json + go test github.com/pingcap/tidb/util/benchdaily -bench BenchmarkDaily \ -date `git log -n1 --date=unix --pretty=format:%cd` \ -commit `git log -n1 --pretty=format:%h` \ -outfile $(TO) diff --git a/distsql/bench_test.go b/distsql/bench_test.go new file mode 100644 index 0000000000000..77f76e0a750e7 --- /dev/null +++ b/distsql/bench_test.go @@ -0,0 +1,74 @@ +// Copyright 2021 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package distsql + +import ( + "context" + "testing" + + "github.com/pingcap/tidb/util/benchdaily" + "github.com/pingcap/tidb/util/chunk" +) + +func BenchmarkSelectResponseChunk_BigResponse(b *testing.B) { + for i := 0; i < b.N; i++ { + b.StopTimer() + sctx := newMockSessionContext() + sctx.GetSessionVars().InitChunkSize = 32 + sctx.GetSessionVars().MaxChunkSize = 1024 + selectResult, colTypes := createSelectNormalByBenchmarkTest(4000, 20000, sctx) + chk := chunk.NewChunkWithCapacity(colTypes, 1024) + b.StartTimer() + for { + err := selectResult.Next(context.TODO(), chk) + if err != nil { + panic(err) + } + if chk.NumRows() == 0 { + break + } + chk.Reset() + } + } +} + +func BenchmarkSelectResponseChunk_SmallResponse(b *testing.B) { + for i := 0; i < b.N; i++ { + b.StopTimer() + sctx := newMockSessionContext() + sctx.GetSessionVars().InitChunkSize = 32 + sctx.GetSessionVars().MaxChunkSize = 1024 + selectResult, colTypes := createSelectNormalByBenchmarkTest(32, 3200, sctx) + chk := chunk.NewChunkWithCapacity(colTypes, 1024) + b.StartTimer() + for { + err := selectResult.Next(context.TODO(), chk) + if err != nil { + panic(err) + } + if chk.NumRows() == 0 { + break + } + chk.Reset() + } + } +} + +func BenchmarkDaily(b *testing.B) { + benchdaily.Run( + BenchmarkSelectResponseChunk_BigResponse, + BenchmarkSelectResponseChunk_SmallResponse, + ) +} diff --git a/distsql/distsql_test.go b/distsql/distsql_test.go index 528ee97b94f7a..75a548c806ced 100644 --- a/distsql/distsql_test.go +++ b/distsql/distsql_test.go @@ -337,50 +337,6 @@ func (r *mockResultSubset) MemSize() int64 { return int64(cap(r.data)) } // RespTime implements kv.ResultSubset interface. func (r *mockResultSubset) RespTime() time.Duration { return 0 } -func BenchmarkSelectResponseChunk_BigResponse(b *testing.B) { - for i := 0; i < b.N; i++ { - b.StopTimer() - sctx := newMockSessionContext() - sctx.GetSessionVars().InitChunkSize = 32 - sctx.GetSessionVars().MaxChunkSize = 1024 - selectResult, colTypes := createSelectNormalByBenchmarkTest(4000, 20000, sctx) - chk := chunk.NewChunkWithCapacity(colTypes, 1024) - b.StartTimer() - for { - err := selectResult.Next(context.TODO(), chk) - if err != nil { - panic(err) - } - if chk.NumRows() == 0 { - break - } - chk.Reset() - } - } -} - -func BenchmarkSelectResponseChunk_SmallResponse(b *testing.B) { - for i := 0; i < b.N; i++ { - b.StopTimer() - sctx := newMockSessionContext() - sctx.GetSessionVars().InitChunkSize = 32 - sctx.GetSessionVars().MaxChunkSize = 1024 - selectResult, colTypes := createSelectNormalByBenchmarkTest(32, 3200, sctx) - chk := chunk.NewChunkWithCapacity(colTypes, 1024) - b.StartTimer() - for { - err := selectResult.Next(context.TODO(), chk) - if err != nil { - panic(err) - } - if chk.NumRows() == 0 { - break - } - chk.Reset() - } - } -} - func newMockSessionContext() sessionctx.Context { ctx := mock.NewContext() ctx.GetSessionVars().StmtCtx = &stmtctx.StatementContext{ diff --git a/executor/benchmark_test.go b/executor/benchmark_test.go index 3dbe99ad96554..b6a5cdde3279d 100644 --- a/executor/benchmark_test.go +++ b/executor/benchmark_test.go @@ -2102,7 +2102,7 @@ func BenchmarkPipelinedRowNumberWindowFunctionExecution(b *testing.B) { } -func TestBenchDaily(t *testing.T) { +func BenchmarkDaily(b *testing.B) { benchdaily.Run( BenchmarkReadLastLinesOfHugeLine, ) diff --git a/expression/bench_test.go b/expression/bench_test.go index c2e29765e0ccc..e164c26a94f85 100644 --- a/expression/bench_test.go +++ b/expression/bench_test.go @@ -2024,7 +2024,7 @@ func (s *testVectorizeSuite2) TestVectorizedFilterConsiderNull(c *C) { ctx.GetSessionVars().EnableVectorizedExpression = dafaultEnableVectorizedExpressionVar } -func TestBenchDaily(t *testing.T) { +func BenchmarkDaily(b *testing.B) { benchdaily.Run( BenchmarkCastIntAsIntRow, BenchmarkCastIntAsIntVec, diff --git a/session/bench_test.go b/session/bench_test.go index f457126e38c52..7febef2ff949a 100644 --- a/session/bench_test.go +++ b/session/bench_test.go @@ -1808,7 +1808,7 @@ func BenchmarkCompileExecutePreparedStmt(b *testing.B) { // The format of the json output is described by the BenchOutput. // Used by this command in the Makefile // make bench-daily TO=xxx.json -func TestBenchDaily(t *testing.T) { +func BenchmarkDaily(b *testing.B) { benchdaily.Run( BenchmarkPreparedPointGet, BenchmarkPointGet, diff --git a/tablecodec/bench_test.go b/tablecodec/bench_test.go index 65af86cd405d6..289982b68b17d 100644 --- a/tablecodec/bench_test.go +++ b/tablecodec/bench_test.go @@ -55,7 +55,7 @@ func BenchmarkDecodeRowKey(b *testing.B) { } } -func TestBenchDaily(t *testing.T) { +func BenchmarkDaily(b *testing.B) { benchdaily.Run( BenchmarkEncodeRowKeyWithHandle, BenchmarkEncodeEndKey, diff --git a/util/benchdaily/bench_daily_test.go b/util/benchdaily/bench_daily_test.go index 2139b1d93502e..eb876477a7133 100644 --- a/util/benchdaily/bench_daily_test.go +++ b/util/benchdaily/bench_daily_test.go @@ -51,7 +51,7 @@ func combineFiles(commitHash string, dateInUnix string, inputFiles []string, out enc.Encode(output) } -func TestBenchDaily(t *testing.T) { +func BenchmarkDaily(b *testing.B) { if !flag.Parsed() { flag.Parse() } diff --git a/util/codec/bench_test.go b/util/codec/bench_test.go index 6081de900a30c..e74a2e251fa37 100644 --- a/util/codec/bench_test.go +++ b/util/codec/bench_test.go @@ -105,7 +105,7 @@ func BenchmarkDecodeOneToChunk(b *testing.B) { } } -func TestBenchDaily(t *testing.T) { +func BenchmarkDaily(b *testing.B) { benchdaily.Run( BenchmarkDecodeWithSize, BenchmarkDecodeWithOutSize, diff --git a/util/rowcodec/bench_test.go b/util/rowcodec/bench_test.go index 5c10fa8065e6c..cd833f1cbdd22 100644 --- a/util/rowcodec/bench_test.go +++ b/util/rowcodec/bench_test.go @@ -92,7 +92,7 @@ func BenchmarkDecode(b *testing.B) { } } -func TestBenchDaily(t *testing.T) { +func BenchmarkDaily(b *testing.B) { benchdaily.Run( BenchmarkEncode, BenchmarkDecode,