@@ -643,11 +643,7 @@ func TestIteratorClose(t *testing.T) {
643
643
}
644
644
}
645
645
646
- var result []Chunk
647
-
648
646
func BenchmarkWrite (b * testing.B ) {
649
- chunks := []Chunk {}
650
-
651
647
entry := & logproto.Entry {
652
648
Timestamp : time .Unix (0 , 0 ),
653
649
Line : testdata .LogString (0 ),
@@ -657,6 +653,7 @@ func BenchmarkWrite(b *testing.B) {
657
653
for _ , f := range HeadBlockFmts {
658
654
for _ , enc := range testEncoding {
659
655
b .Run (fmt .Sprintf ("%v-%v" , f , enc ), func (b * testing.B ) {
656
+ uncompressedBytes , compressedBytes := 0 , 0
660
657
for n := 0 ; n < b .N ; n ++ {
661
658
c := NewMemChunk (enc , f , testBlockSize , testTargetSize )
662
659
// adds until full so we trigger cut which serialize using gzip
@@ -666,9 +663,11 @@ func BenchmarkWrite(b *testing.B) {
666
663
entry .Line = testdata .LogString (i )
667
664
i ++
668
665
}
669
- chunks = append (chunks , c )
666
+ uncompressedBytes += c .UncompressedSize ()
667
+ compressedBytes += c .CompressedSize ()
670
668
}
671
- result = chunks
669
+ b .SetBytes (int64 (uncompressedBytes ) / int64 (b .N ))
670
+ b .ReportMetric (float64 (compressedBytes )/ float64 (uncompressedBytes )* 100 , "%compressed" )
672
671
})
673
672
}
674
673
}
@@ -685,23 +684,17 @@ func (nomatchPipeline) ProcessString(_ int64, line string) (string, log.LabelsRe
685
684
}
686
685
687
686
func BenchmarkRead (b * testing.B ) {
688
- type res struct {
689
- name string
690
- speed float64
691
- }
692
- result := []res {}
693
687
for _ , bs := range testBlockSizes {
694
688
for _ , enc := range testEncoding {
695
689
name := fmt .Sprintf ("%s_%s" , enc .String (), humanize .Bytes (uint64 (bs )))
696
690
b .Run (name , func (b * testing.B ) {
697
691
chunks , size := generateData (enc , 5 , bs , testTargetSize )
692
+ _ , ctx := stats .NewContext (context .Background ())
698
693
b .ResetTimer ()
699
- bytesRead := uint64 (0 )
700
- now := time .Now ()
701
694
for n := 0 ; n < b .N ; n ++ {
702
695
for _ , c := range chunks {
703
696
// use forward iterator for benchmark -- backward iterator does extra allocations by keeping entries in memory
704
- iterator , err := c .Iterator (context . Background () , time .Unix (0 , 0 ), time .Now (), logproto .FORWARD , nomatchPipeline {})
697
+ iterator , err := c .Iterator (ctx , time .Unix (0 , 0 ), time .Now (), logproto .FORWARD , nomatchPipeline {})
705
698
if err != nil {
706
699
panic (err )
707
700
}
@@ -712,24 +705,23 @@ func BenchmarkRead(b *testing.B) {
712
705
b .Fatal (err )
713
706
}
714
707
}
715
- bytesRead += size
716
708
}
717
- result = append (result , res {
718
- name : name ,
719
- speed : float64 (bytesRead ) / time .Since (now ).Seconds (),
720
- })
709
+ b .SetBytes (int64 (size ))
721
710
})
711
+ }
712
+ }
722
713
723
- name = fmt .Sprintf ("sample_%s_%s" , enc .String (), humanize .Bytes (uint64 (bs )))
724
-
714
+ for _ , bs := range testBlockSizes {
715
+ for _ , enc := range testEncoding {
716
+ name := fmt .Sprintf ("sample_%s_%s" , enc .String (), humanize .Bytes (uint64 (bs )))
725
717
b .Run (name , func (b * testing.B ) {
726
718
chunks , size := generateData (enc , 5 , bs , testTargetSize )
719
+ _ , ctx := stats .NewContext (context .Background ())
727
720
b .ResetTimer ()
728
721
bytesRead := uint64 (0 )
729
- now := time .Now ()
730
722
for n := 0 ; n < b .N ; n ++ {
731
723
for _ , c := range chunks {
732
- iterator := c .SampleIterator (context . Background () , time .Unix (0 , 0 ), time .Now (), countExtractor )
724
+ iterator := c .SampleIterator (ctx , time .Unix (0 , 0 ), time .Now (), countExtractor )
733
725
for iterator .Next () {
734
726
_ = iterator .Sample ()
735
727
}
@@ -739,19 +731,10 @@ func BenchmarkRead(b *testing.B) {
739
731
}
740
732
bytesRead += size
741
733
}
742
- result = append (result , res {
743
- name : name ,
744
- speed : float64 (bytesRead ) / time .Since (now ).Seconds (),
745
- })
734
+ b .SetBytes (int64 (bytesRead ) / int64 (b .N ))
746
735
})
747
736
}
748
737
}
749
- sort .Slice (result , func (i , j int ) bool {
750
- return result [i ].speed > result [j ].speed
751
- })
752
- for _ , r := range result {
753
- fmt .Printf ("%s: %.2f MB/s\n " , r .name , r .speed / 1024 / 1024 )
754
- }
755
738
}
756
739
757
740
func BenchmarkBackwardIterator (b * testing.B ) {
0 commit comments