Files
mostlymatter/server/channels/app/imaging/decode_bench_test.go
Agniva De Sarker efaa6264cc MM-53032: Fix module path after repo rename (#23689)
It was a good decision in hindsight to keep the public module as 0.x
because this would have been a breaking change again.

https://mattermost.atlassian.net/browse/MM-53032
```release-note
Changed the Go module path from github.com/mattermost/mattermost-server/server/v8 to github.com/mattermost/mattermost/server/v8.

For the public facing module, it's path is also changed from github.com/mattermost/mattermost-server/server/public to github.com/mattermost/mattermost/server/public
```
2023-06-11 10:54:35 +05:30

90 строки
1.8 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package imaging
import (
"fmt"
"os"
"runtime"
"sync"
"testing"
"github.com/mattermost/mattermost/server/v8/channels/utils/fileutils"
"github.com/stretchr/testify/require"
)
func BenchmarkDecoderDecode(b *testing.B) {
n := runtime.NumCPU()
for k := 1; k <= n; k++ {
b.Run(fmt.Sprintf("%d concurrency", k), func(b *testing.B) {
d, err := NewDecoder(DecoderOptions{
ConcurrencyLevel: k,
})
require.NotNil(b, d)
require.NoError(b, err)
imgDir, ok := fileutils.FindDir("tests")
require.True(b, ok)
b.ResetTimer()
var wg sync.WaitGroup
for i := 0; i < b.N; i++ {
b.StopTimer()
wg.Add(1)
imgFile, err := os.Open(imgDir + "/fill_test_opaque.png")
require.NoError(b, err)
defer imgFile.Close()
b.StartTimer()
go func() {
defer wg.Done()
img, _, err := d.Decode(imgFile)
require.NoError(b, err)
require.NotNil(b, img)
}()
}
wg.Wait()
})
}
}
func BenchmarkDecoderDecodeMemBounded(b *testing.B) {
n := runtime.NumCPU()
for k := 1; k <= n; k++ {
b.Run(fmt.Sprintf("%d concurrency", k), func(b *testing.B) {
d, err := NewDecoder(DecoderOptions{
ConcurrencyLevel: k,
})
require.NotNil(b, d)
require.NoError(b, err)
imgDir, ok := fileutils.FindDir("tests")
require.True(b, ok)
b.ResetTimer()
var wg sync.WaitGroup
for i := 0; i < b.N; i++ {
b.StopTimer()
wg.Add(1)
imgFile, err := os.Open(imgDir + "/fill_test_opaque.png")
require.NoError(b, err)
defer imgFile.Close()
b.StartTimer()
go func() {
defer wg.Done()
img, _, release, err := d.DecodeMemBounded(imgFile)
require.NoError(b, err)
require.NotNil(b, img)
release()
}()
}
wg.Wait()
})
}
}