forked from shgopher/GOFamily
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_test.go
40 lines (33 loc) · 960 Bytes
/
1_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
package main
import (
"fmt"
"testing"
)
func TestP(t *testing.T) {
fmt.Println(P("abcdefghijklmnopqrstuvwxyz", "abcde")) // 头
fmt.Println(P("abcdefghijklmnopqrstuvwxyz", "wxyz")) // 尾
fmt.Println(P("abcdefghijklmnopqrstuvwxyz", "jklm")) // 普通
fmt.Println(P("abcdefghijklmnopqrstuvwxyz", "bblm")) // 没有
// true
// true
// true
// false
}
func BenchmarkP(b *testing.B) {
for i := 0; i < b.N; i++ {
P("abcdefghijklmnopqrstuvwxyz", "foew")
}
}
func BenchmarkP1(b *testing.B) {
for i := 0; i < b.N; i++ {
P("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "foew")
}
}
func BenchmarkP2(b *testing.B) {
for i := 0; i < b.N; i++ {
P("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "foew")
}
}
// BenchmarkP-4 10000000 167 ns/op
// BenchmarkP1-4 5000000 342 ns/op
// BenchmarkP2-4 2000000 837 ns/op