Skip to content

Commit

Permalink
Benchmark the speaker conversion from samples to bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkKremer committed Nov 2, 2023
1 parent 198a5e1 commit 6e88eec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 5 additions & 3 deletions speaker/speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
package speaker

import (
"github.com/ebitengine/oto/v3"
"github.com/gopxl/beep"
"github.com/pkg/errors"
"io"
"sync"

"github.com/ebitengine/oto/v3"
"github.com/pkg/errors"

"github.com/gopxl/beep"
)

const channelCount = 2
Expand Down
36 changes: 36 additions & 0 deletions speaker/speaker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package speaker

import (
"fmt"
"io"
"testing"

"github.com/gopxl/beep/internal/testtools"
)

func BenchmarkSampleReader_Read(b *testing.B) {
// note: must be multiples of bytesPerSample
bufferSizes := []int{64, 512, 8192, 32768}

for _, bs := range bufferSizes {
b.Run(fmt.Sprintf("with buffer size %d", bs), func(b *testing.B) {
s, _ := testtools.RandomDataStreamer(b.N)
r := newReaderFromStreamer(s)
buf := make([]byte, bs)

b.StartTimer()
for {
n, err := r.Read(buf)
if err == io.EOF {
break
}
if err != nil {
panic(err)
}
if n != len(buf) {
break
}
}
})
}
}

0 comments on commit 6e88eec

Please sign in to comment.