From 421a127f11a3849007d36b142261cc8115a209af Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Thu, 17 Dec 2015 15:38:51 -0700 Subject: [PATCH] Add indirectIndex.UnmarshalBinary benchmark --- tsdb/engine/tsm1/reader_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tsdb/engine/tsm1/reader_test.go b/tsdb/engine/tsm1/reader_test.go index 69d87a93fe..4380157270 100644 --- a/tsdb/engine/tsm1/reader_test.go +++ b/tsdb/engine/tsm1/reader_test.go @@ -2,6 +2,7 @@ package tsm1_test import ( "bytes" + "fmt" "os" "testing" "time" @@ -721,3 +722,23 @@ func TestBlockIterator_Sorted(t *testing.T) { t.Fatalf("value count mismatch: got %v, exp %v", got, exp) } } + +func BenchmarkIndirectIndex_UnmarshalBinary(b *testing.B) { + index := tsm1.NewDirectIndex() + for i := 0; i < 100000; i++ { + index.Add(fmt.Sprintf("cpu-%d", i), tsm1.BlockFloat64, time.Unix(int64(i*2), 0), time.Unix(int64(i*2+1), 0), 10, 100) + } + + bytes, err := index.MarshalBinary() + if err != nil { + b.Fatalf("unexpected error marshaling index: %v", err) + } + + indirect := tsm1.NewIndirectIndex() + b.ResetTimer() + for i := 0; i < b.N; i++ { + if err := indirect.UnmarshalBinary(bytes); err != nil { + b.Fatalf("unexpected error unmarshaling index: %v", err) + } + } +}