Files
tidb/util/codec/bench_test.go
Shen Li 558ba06368 decode with value size (#1641)
Add size parameter for Decode to reduce slice growth
BenchmarkDecodeWithSize-8 300000 6153 ns/op
BenchmarkDecodeWithOutSize-8 200000 11934 ns/op
2016-08-26 10:44:03 +08:00

50 lines
1.1 KiB
Go

// Copyright 2016 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 codec
import (
"testing"
"github.com/pingcap/tidb/util/types"
)
var valueCnt = 100
func composeEncodedData(size int) []byte {
values := make([]types.Datum, 0, size)
for i := 0; i < size; i++ {
values = append(values, types.NewDatum(i))
}
bs, _ := EncodeValue(nil, values...)
return bs
}
func BenchmarkDecodeWithSize(b *testing.B) {
b.StopTimer()
bs := composeEncodedData(valueCnt)
b.StartTimer()
for i := 0; i < b.N; i++ {
Decode(bs, valueCnt)
}
}
func BenchmarkDecodeWithOutSize(b *testing.B) {
b.StopTimer()
bs := composeEncodedData(valueCnt)
b.StartTimer()
for i := 0; i < b.N; i++ {
Decode(bs, 1)
}
}