mirror of
				https://github.com/datarhei/core.git
				synced 2025-10-31 19:32:56 +08:00 
			
		
		
		
	Extend benchmark with different size
This commit is contained in:
		| @@ -2,12 +2,15 @@ package compress | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"net/http" | ||||
| 	"net/http/httptest" | ||||
| 	"os" | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/datarhei/core/v16/math/rand" | ||||
|  | ||||
| 	"github.com/andybalholm/brotli" | ||||
| 	"github.com/klauspost/compress/gzip" | ||||
| 	"github.com/klauspost/compress/zstd" | ||||
| @@ -287,15 +290,20 @@ func TestCompressWithStatic(t *testing.T) { | ||||
| func BenchmarkCompress(b *testing.B) { | ||||
| 	schemes := getTestcases() | ||||
|  | ||||
| 	for i := 1; i <= 18; i++ { | ||||
| 		datalen := 2 << i | ||||
| 		data := []byte(rand.String(datalen)) | ||||
|  | ||||
| 		for scheme := range schemes { | ||||
| 		b.Run(scheme.String(), func(b *testing.B) { | ||||
| 			name := fmt.Sprintf("%s-%d", scheme.String(), datalen) | ||||
| 			b.Run(name, func(b *testing.B) { | ||||
| 				e := echo.New() | ||||
|  | ||||
| 				req := httptest.NewRequest(http.MethodGet, "/", nil) | ||||
| 				req.Header.Set(echo.HeaderAcceptEncoding, scheme.String()) | ||||
|  | ||||
| 				h := NewWithConfig(Config{Level: BestSpeed, Schemes: []Scheme{scheme}})(func(c echo.Context) error { | ||||
| 				c.Response().Write([]byte("testtesttesttesttesttesttesttesttesttesttesttesttest")) | ||||
| 					c.Response().Write(data) | ||||
| 					return nil | ||||
| 				}) | ||||
|  | ||||
| @@ -310,8 +318,9 @@ func BenchmarkCompress(b *testing.B) { | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func BenchmarkCompressLarge(b *testing.B) { | ||||
| func BenchmarkCompressJSON(b *testing.B) { | ||||
| 	data, err := os.ReadFile("./fixtures/processList.json") | ||||
| 	require.NoError(b, err) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Ingo Oppermann
					Ingo Oppermann