-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnw_test.go
80 lines (69 loc) · 2.49 KB
/
nw_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package sequencing
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func similarity(a byte, b byte) int {
if a == b {
return 1
}
return -1
}
func similarityStrings(a string, b string) int {
if a == b {
return 1
}
return -1
}
const maxSize = 5000
func TestNeedlemanWunsch(t *testing.T) {
a := []byte("ABCDEF")
b := []byte("ABCCDEF")
f := make([][]int, maxSize)
for i := 0; i < maxSize; i++ {
f[i] = make([]int, maxSize)
}
z, w := NeedlemanWunsch(a, b, -1, similarity, f)
fmt.Printf("%s\n%s\n", string(z), string(w))
assert.Equal(t, "AB-CDEF", string(z))
assert.Equal(t, "ABCCDEF", string(w))
}
func BenchmarkNeedlemanWunsch(b *testing.B) {
b.Run("6 char string", func(b *testing.B) {
x := []byte("ABCDEF")
y := []byte("ABCCDEF")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
NeedlemanWunsch(x, y, -1, similarity, nil)
}
})
b.Run("25-30 char string", func(b *testing.B) {
x := []byte("This is a longer string")
y := []byte("This is a much longer string")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
NeedlemanWunsch(x, y, -1, similarity, nil)
}
})
b.Run("Long log line", func(b *testing.B) {
x := []byte("10__8__0__146 kernel process Google Chrome Ca[3955] caught causing excessive wakeups. Observed wakeups rate (per sec): 392; Maximum permitted wakeups rate (per sec): 150; Observation period: 300 seconds; Task lifetime number of wakeups: 317314")
y := []byte("10__8__0__146 kernel process Sublime Text[802] caught causing excessive wakeups. Observed wakeups rate (per sec): 233; Maximum permitted wakeups rate (per sec): 150; Observation period: 300 seconds; Task lifetime number of wakeups: 95333")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
NeedlemanWunsch(x, y, -1, similarity, nil)
}
})
b.Run("Long log line reuse", func(b *testing.B) {
x := []byte("10__8__0__146 kernel process Google Chrome Ca[3955] caught causing excessive wakeups. Observed wakeups rate (per sec): 392; Maximum permitted wakeups rate (per sec): 150; Observation period: 300 seconds; Task lifetime number of wakeups: 317314")
y := []byte("10__8__0__146 kernel process Sublime Text[802] caught causing excessive wakeups. Observed wakeups rate (per sec): 233; Maximum permitted wakeups rate (per sec): 150; Observation period: 300 seconds; Task lifetime number of wakeups: 95333")
f := make([][]int, maxSize)
for i := 0; i < maxSize; i++ {
f[i] = make([]int, maxSize)
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
NeedlemanWunsch(x, y, -1, similarity, f)
}
})
}