github.com/TeaOSLab/EdgeNode@v1.3.8/internal/compressions/writer_deflate_test.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package compressions_test
     4  
     5  import (
     6  	"bytes"
     7  	"github.com/TeaOSLab/EdgeNode/internal/compressions"
     8  	"strings"
     9  	"testing"
    10  )
    11  
    12  func BenchmarkDeflateWriter_Write(b *testing.B) {
    13  	var data = []byte(strings.Repeat("A", 1024))
    14  
    15  	for i := 0; i < b.N; i++ {
    16  		var buf = &bytes.Buffer{}
    17  		writer, err := compressions.NewDeflateWriter(buf, 5)
    18  		if err != nil {
    19  			b.Fatal(err)
    20  		}
    21  
    22  		for j := 0; j < 100; j++ {
    23  			_, err = writer.Write(data)
    24  			if err != nil {
    25  				b.Fatal(err)
    26  			}
    27  
    28  			/**err = writer.Flush()
    29  			if err != nil {
    30  				b.Fatal(err)
    31  			}**/
    32  		}
    33  
    34  		_ = writer.Close()
    35  	}
    36  }