mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-04 01:54:28 +00:00
c5ffc971c5
* badger v2 investigation * buf pool - use native New method and avoid double checks * db.Open prototype * db.Tx/Bucket/Cursor prototypes * Chained config * Item concept added * save changes to test on master * make hack resumable * Design document v0 * Cursor concept * less brackets syntax of cursor builder * benchmarks * cleanup fs * test for context cancelations * test for context cancelations * test for cursor.Prefix option * add ForEachKey method * add ForEachKey method * add naming explanation * experiment of non-pointers cursor/bucket * .Bucket() and .Cursor() doesn't returns error * .Bucket() and .Cursor() doesn't returns error * .Bucket() and .Cursor() doesn't returns error * remove CursorOpts concept * more test-cases * simplify open api * Tx, Bucket, Cursor - now are interfaces * Tx, Bucket, Cursor - now are interfaces * switch to interfaces * rebase master Co-authored-by: alex.sharov <alex.sharov@lazada.com>
144 lines
3.2 KiB
Go
144 lines
3.2 KiB
Go
// Copyright 2019 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package remotedbserver
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb/remote"
|
|
"github.com/ugorji/go/codec"
|
|
)
|
|
|
|
func BenchmarkSerialize(b *testing.B) {
|
|
k := make([]byte, 50)
|
|
v := make([]byte, 500)
|
|
var w bytes.Buffer
|
|
var handle codec.CborHandle
|
|
handle.WriterBufferSize = 1024
|
|
encoder := codec.NewEncoder(&w, &handle)
|
|
|
|
b.Run("encodeKeyValue()", func(b *testing.B) {
|
|
encoder.Reset(&w)
|
|
w.Reset()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
_ = encoder.Encode(remote.ResponseOk)
|
|
_ = encodeKeyValue(encoder, k, v)
|
|
}
|
|
})
|
|
b.Run("encoder.Encode(&k)", func(b *testing.B) {
|
|
encoder.Reset(&w)
|
|
w.Reset()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
_ = encoder.Encode(remote.ResponseOk)
|
|
_ = encoder.Encode(&k)
|
|
_ = encoder.Encode(&v)
|
|
}
|
|
})
|
|
b.Run("encoder.Encode(k)", func(b *testing.B) {
|
|
encoder.Reset(&w)
|
|
w.Reset()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
_ = encoder.Encode(remote.ResponseOk)
|
|
_ = encoder.Encode(k)
|
|
_ = encoder.Encode(v)
|
|
}
|
|
})
|
|
b.Run("encoder.MustEncode(&k)", func(b *testing.B) {
|
|
encoder.Reset(&w)
|
|
w.Reset()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
encoder.MustEncode(remote.ResponseOk)
|
|
encoder.MustEncode(&k)
|
|
encoder.MustEncode(&v)
|
|
}
|
|
})
|
|
b.Run("encoder.MustEncode(k)", func(b *testing.B) {
|
|
encoder.Reset(&w)
|
|
w.Reset()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
encoder.MustEncode(remote.ResponseOk)
|
|
encoder.MustEncode(k)
|
|
encoder.MustEncode(v)
|
|
}
|
|
})
|
|
b.Run("Encode(struct)", func(b *testing.B) {
|
|
encoder.Reset(&w)
|
|
w.Reset()
|
|
b.ResetTimer()
|
|
|
|
type kv struct {
|
|
K []byte
|
|
V []byte
|
|
}
|
|
type a struct {
|
|
C remote.ResponseCode
|
|
kv
|
|
}
|
|
x := &a{}
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
x.C = remote.ResponseOk
|
|
x.K = k
|
|
x.V = v
|
|
encoder.MustEncode(x)
|
|
}
|
|
})
|
|
|
|
M := 10 * 1000
|
|
b.Run("10K Encode(&k, &v) nobuf", func(b *testing.B) {
|
|
encoder.Reset(&w)
|
|
w.Reset()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
encoder.MustEncode(remote.ResponseOk)
|
|
for i := 0; i < M; i++ {
|
|
encoder.MustEncode(&k)
|
|
encoder.MustEncode(&v)
|
|
}
|
|
}
|
|
})
|
|
b.Run("Encode([10K]k, [10K]v)", func(b *testing.B) {
|
|
encoder.Reset(&w)
|
|
w.Reset()
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
keys := make([][]byte, M)
|
|
values := make([][]byte, M)
|
|
for i := 0; i < M; i++ {
|
|
keys[i] = k
|
|
values[i] = v
|
|
}
|
|
encoder.MustEncode(remote.ResponseOk)
|
|
encoder.MustEncode(&keys)
|
|
encoder.MustEncode(&values)
|
|
}
|
|
})
|
|
}
|