Skip to content

Commit

Permalink
Add BlockWriter bench (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Dec 20, 2019
1 parent b80e73d commit d2269ab
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions mkvcore/blockwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,50 @@ func TestBlockWriter_WithSeekHead(t *testing.T) {
}
})
}

func BenchmarkBlockWriter_InitFinalize(b *testing.B) {
tracks := []TrackDescription{
{TrackNumber: 1},
}

for i := 0; i < b.N; i++ {
buf := buffercloser.New()
ws, err := NewSimpleBlockWriter(buf, tracks,
WithBlockInterceptor(NewMultiTrackBlockSorter(10, BlockSorterDropOutdated)),
)
if err != nil {
b.Fatalf("Failed to create BlockWriter: %v", err)
}
for _, w := range ws {
w.Close()
}
}
}

func BenchmarkBlockWriter_SimpleBlock(b *testing.B) {
tracks := []TrackDescription{
{TrackNumber: 1},
}

buf := buffercloser.New()
ws, err := NewSimpleBlockWriter(buf, tracks,
WithBlockInterceptor(NewMultiTrackBlockSorter(10, BlockSorterDropOutdated)),
)
if err != nil {
b.Fatalf("Failed to create BlockWriter: %v", err)
}

data := []byte{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, w := range ws {
if _, err := w.Write(true, int64(i*20), data); err != nil {
b.Fatalf("Failed to Write: %v", err)
}
}
}
b.StopTimer()
for _, w := range ws {
w.Close()
}
}

0 comments on commit d2269ab

Please sign in to comment.