-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark TagValueFromEncodedTagsFast
- Loading branch information
1 parent
d3a8c38
commit c4296b6
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/dbnode/storage/index/convert/decoder_fast_benchmark_test.go
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,74 @@ | ||
package convert | ||
|
||
import ( | ||
"github.com/m3db/m3/src/x/checked" | ||
"github.com/m3db/m3/src/x/pool" | ||
"github.com/m3db/m3/src/x/serialize" | ||
"github.com/stretchr/testify/require" | ||
"math/rand" | ||
"testing" | ||
) | ||
|
||
type encodedTagsWithTagName struct { | ||
encodedTags, tagName []byte | ||
} | ||
|
||
func BenchmarkTagValueFromEncodedTagsFast(b *testing.B) { | ||
testData, err := prepareData(b) | ||
require.NoError(b, err) | ||
|
||
b.ResetTimer() | ||
for i := range testData { | ||
_, _, err := serialize.TagValueFromEncodedTagsFast(testData[i].encodedTags, | ||
testData[i].tagName) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
func BenchmarkTagValueFromEncodedTagsFast2(b *testing.B) { | ||
testData, err := prepareData(b) | ||
require.NoError(b, err) | ||
|
||
b.ResetTimer() | ||
for i := range testData { | ||
_, _, err := serialize.TagValueFromEncodedTagsFast2(testData[i].encodedTags, | ||
testData[i].tagName) | ||
require.NoError(b, err) | ||
} | ||
} | ||
|
||
func prepareData(b *testing.B) ([]encodedTagsWithTagName, error) { | ||
data, err := prepareIDAndEncodedTags(b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
decoderPool := serialize.NewTagDecoderPool( | ||
serialize.NewTagDecoderOptions(serialize.TagDecoderOptionsConfig{}), | ||
pool.NewObjectPoolOptions(), | ||
) | ||
decoderPool.Init() | ||
decoder := decoderPool.Get() | ||
defer decoder.Close() | ||
|
||
var tagNames [][]byte | ||
decoder.Reset(checked.NewBytes(data[0].encodedTags, nil)) | ||
for decoder.Next() { | ||
tagNames = append(tagNames, clone(decoder.Current().Name.Bytes())) | ||
} | ||
tagNames = append(tagNames, []byte("not_exist")) | ||
|
||
var ( | ||
result = make([]encodedTagsWithTagName, 0, b.N) | ||
rnd = rand.New(rand.NewSource(42)) | ||
) | ||
|
||
for i := 0; i < b.N; i++ { | ||
result = append(result, encodedTagsWithTagName{ | ||
encodedTags: data[i].encodedTags, | ||
tagName: tagNames[rnd.Intn(len(tagNames))], | ||
}) | ||
} | ||
|
||
return result, nil | ||
} |
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