github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/audio/benchmark/gen_test.go (about) 1 package benchmark_audio 2 3 import ( 4 "strconv" 5 "testing" 6 ) 7 8 const ( 9 SampleRate = 44100 10 TestFrameCount = SampleRate / 10 11 TestBytes = TestFrameCount * 4 12 ) 13 14 var ( 15 tmp = make([]float32, 7*TestFrameCount) 16 tmp_1 = make([][1]float32, TestFrameCount) 17 tmp_2 = make([][2]float32, TestFrameCount) 18 tmp_5 = make([][5]float32, TestFrameCount) 19 tmp_7 = make([][7]float32, TestFrameCount) 20 ) 21 22 func BenchmarkSawtooth_Dynamic(b *testing.B) { 23 for _, nch := range []int{1, 2, 5, 7} { 24 b.Run("Ch"+strconv.Itoa(nch), func(b *testing.B) { 25 b.SetBytes(TestBytes) 26 for i := 0; i < b.N; i++ { 27 buf := &Buffer{byte(nch), tmp[:TestFrameCount*nch]} 28 Sawtooth_Dynamic(buf, SampleRate, 440) 29 } 30 }) 31 } 32 } 33 34 func BenchmarkSawtooth_Switch(b *testing.B) { 35 for _, nch := range []int{1, 2, 5, 7} { 36 b.Run("Ch"+strconv.Itoa(nch), func(b *testing.B) { 37 b.SetBytes(TestBytes) 38 for i := 0; i < b.N; i++ { 39 buf := &Buffer{byte(nch), tmp[:TestFrameCount*nch]} 40 Sawtooth_Switch(buf, SampleRate, 440) 41 } 42 }) 43 } 44 } 45 46 func BenchmarkSawtooth_Baseline(b *testing.B) { 47 b.Run("Ch1", func(b *testing.B) { 48 b.SetBytes(TestBytes) 49 for i := 0; i < b.N; i++ { 50 Sawtooth_Baseline_Ch1(Buffer_Ch1(tmp_1), SampleRate, 440) 51 } 52 }) 53 54 b.Run("Ch2", func(b *testing.B) { 55 b.SetBytes(TestBytes) 56 for i := 0; i < b.N; i++ { 57 Sawtooth_Baseline_Ch2(Buffer_Ch2(tmp_2), SampleRate, 440) 58 } 59 }) 60 61 b.Run("Ch5", func(b *testing.B) { 62 b.SetBytes(TestBytes) 63 for i := 0; i < b.N; i++ { 64 Sawtooth_Baseline_Ch5(Buffer_Ch5(tmp_5), SampleRate, 440) 65 } 66 }) 67 68 b.Run("Ch7", func(b *testing.B) { 69 b.SetBytes(TestBytes) 70 for i := 0; i < b.N; i++ { 71 Sawtooth_Baseline_Ch7(Buffer_Ch7(tmp_7), SampleRate, 440) 72 } 73 }) 74 }