-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rowcodec: make rowcodec can be used for mocktikv & unistore (#13774)
- Loading branch information
Showing
7 changed files
with
1,543 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2019 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, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package rowcodec_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/pingcap/parser/mysql" | ||
"github.com/pingcap/tidb/sessionctx/stmtctx" | ||
"github.com/pingcap/tidb/tablecodec" | ||
"github.com/pingcap/tidb/types" | ||
"github.com/pingcap/tidb/util/chunk" | ||
"github.com/pingcap/tidb/util/rowcodec" | ||
) | ||
|
||
func BenchmarkEncode(b *testing.B) { | ||
b.ReportAllocs() | ||
oldRow := types.MakeDatums(1, "abc", 1.1) | ||
var xb rowcodec.Encoder | ||
var buf []byte | ||
colIDs := []int64{1, 2, 3} | ||
var err error | ||
for i := 0; i < b.N; i++ { | ||
buf, err = xb.Encode(nil, colIDs, oldRow, buf) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkEncodeFromOldRow(b *testing.B) { | ||
b.ReportAllocs() | ||
oldRow := types.MakeDatums(1, "abc", 1.1) | ||
oldRowData, err := tablecodec.EncodeRow(new(stmtctx.StatementContext), oldRow, []int64{1, 2, 3}, nil, nil) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
var xb rowcodec.Encoder | ||
var buf []byte | ||
for i := 0; i < b.N; i++ { | ||
buf, err = rowcodec.EncodeFromOldRow(&xb, nil, oldRowData, buf) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkDecode(b *testing.B) { | ||
b.ReportAllocs() | ||
oldRow := types.MakeDatums(1, "abc", 1.1) | ||
colIDs := []int64{-1, 2, 3} | ||
tps := []*types.FieldType{ | ||
types.NewFieldType(mysql.TypeLonglong), | ||
types.NewFieldType(mysql.TypeString), | ||
types.NewFieldType(mysql.TypeDouble), | ||
} | ||
var xb rowcodec.Encoder | ||
xRowData, err := xb.Encode(nil, colIDs, oldRow, nil) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
cols := make([]rowcodec.ColInfo, len(tps)) | ||
for i, tp := range tps { | ||
cols[i] = rowcodec.ColInfo{ | ||
ID: colIDs[i], | ||
Tp: int32(tp.Tp), | ||
Flag: int32(tp.Flag), | ||
Flen: tp.Flen, | ||
Decimal: tp.Decimal, | ||
Elems: tp.Elems, | ||
} | ||
} | ||
decoder := rowcodec.NewChunkDecoder(cols, -1, nil, time.Local) | ||
chk := chunk.NewChunkWithCapacity(tps, 1) | ||
for i := 0; i < b.N; i++ { | ||
chk.Reset() | ||
err = decoder.DecodeToChunk(xRowData, 1, chk) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.