-
Notifications
You must be signed in to change notification settings - Fork 4
/
freeze_test.go
57 lines (51 loc) · 1.03 KB
/
freeze_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package snd
import (
"testing"
"time"
"dasa.cc/signal"
)
func TestRingcopy(t *testing.T) {
xs := []float64{1, 2, 3, 4}
tds := []struct {
dn int
off int
ret int
want []float64
}{
{2, 2, 0, []float64{3, 4}},
{8, 2, 2, []float64{3, 4, 1, 2, 3, 4, 1, 2}},
}
for i, td := range tds {
have := make([]float64, td.dn)
r := ringcopy(have, xs, td.off)
if r != td.ret {
t.Errorf("tds[%v] returned %v, want %v", i, r, td.ret)
}
for j, x := range td.want {
if x != have[j] {
t.Errorf("tds[%v] have %+v, want %+v", i, have, td.want)
break
}
}
}
}
func BenchmarkRingcopy(b *testing.B) {
// src := []float64(ExpDecay())
src := make(signal.Discrete, 32)
src.Sample(signal.ExpDecayFunc, 1./32, 0)
dst := make([]float64, 256)
r := 0
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
r = ringcopy(dst, src, r)
}
}
func BenchmarkFreeze(b *testing.B) {
frz := NewFreeze(1*time.Second, newunit())
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
frz.Prepare(uint64(n + 1))
}
}