Add benchmark for MediaService.GetAudioSegment
This commit is contained in:
parent
6d8b1beba7
commit
468ddf4e9a
|
@ -120,6 +120,48 @@ func TestGetAudioSegment(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkGetAudioSegment(b *testing.B) {
|
||||||
|
const (
|
||||||
|
startFrame = 0
|
||||||
|
endFrame = 1323000
|
||||||
|
channels = 2
|
||||||
|
fixturePath = "testdata/tone-44100-stereo-int16-30000ms.raw"
|
||||||
|
fixtureLen = 5292000
|
||||||
|
numBins = 2000
|
||||||
|
)
|
||||||
|
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
b.StopTimer()
|
||||||
|
|
||||||
|
expectedBytes := (endFrame - startFrame) * int64(channels) * media.SizeOfInt16
|
||||||
|
|
||||||
|
audioFile, err := os.Open(fixturePath)
|
||||||
|
require.NoError(b, err)
|
||||||
|
audioData := io.NopCloser(io.LimitReader(audioFile, int64(expectedBytes)))
|
||||||
|
|
||||||
|
mediaSetID := uuid.New()
|
||||||
|
mediaSet := store.MediaSet{ID: mediaSetID, AudioChannels: channels}
|
||||||
|
|
||||||
|
store := &mocks.Store{}
|
||||||
|
store.On("GetMediaSet", mock.Anything, mediaSetID).Return(mediaSet, nil)
|
||||||
|
|
||||||
|
s3Client := &mocks.S3Client{}
|
||||||
|
s3Client.
|
||||||
|
On("GetObject", mock.Anything, mock.Anything).
|
||||||
|
Return(&s3.GetObjectOutput{Body: audioData, ContentLength: fixtureLen}, nil)
|
||||||
|
s3API := media.S3API{S3Client: s3Client, S3PresignClient: &mocks.S3PresignClient{}}
|
||||||
|
|
||||||
|
service := media.NewMediaSetService(store, nil, s3API, config.Config{}, zap.NewNop())
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
_, err = service.GetAudioSegment(context.Background(), mediaSetID, startFrame, endFrame, numBins)
|
||||||
|
b.StopTimer()
|
||||||
|
|
||||||
|
require.NoError(b, err)
|
||||||
|
audioFile.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type testReader struct {
|
type testReader struct {
|
||||||
count int
|
count int
|
||||||
data [][]byte
|
data [][]byte
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue