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