-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch-Insert-Position_test.go
83 lines (74 loc) · 1.84 KB
/
Search-Insert-Position_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
81
82
83
package searchinsertposition
import "testing"
var tests = []struct {
arg1 []int
arg2 int
want int
}{
{
arg1: []int{1, 3, 5, 6},
arg2: 5,
want: 2,
},
{
arg1: []int{1, 3, 5, 6},
arg2: 2,
want: 1,
},
{
arg1: []int{1, 3, 5, 6},
arg2: 7,
want: 4,
},
{
arg1: []int{1, 3, 5, 6},
arg2: 0,
want: 0,
},
}
func TestSearchInsertBurst(t *testing.T) {
for _, tt := range tests {
if got := SearchInsertBurst(tt.arg1, tt.arg2); got != tt.want {
t.Errorf("got = %v, want = %v", got, tt.want)
}
}
}
func TestSearchInsertBisection(t *testing.T) {
for _, tt := range tests {
if got := SearchInsertBisection(tt.arg1, tt.arg2); got != tt.want {
t.Errorf("got = %v, want = %v", got, tt.want)
}
}
}
func TestSearchInsertBisection2(t *testing.T) {
for _, tt := range tests {
if got := SearchInsertBisection2(tt.arg1, tt.arg2); got != tt.want {
t.Errorf("got = %v, want = %v", got, tt.want)
}
}
}
func BenchmarkSearchInsertBurst(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
SearchInsertBurst(tests[0].arg1, tests[0].arg2)
}
}
func BenchmarkSearchInsertBisection(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
SearchInsertBisection(tests[0].arg1, tests[0].arg2)
}
}
func BenchmarkSearchInsertBisection2(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
SearchInsertBisection2(tests[0].arg1, tests[0].arg2)
}
}
/*
go test -benchmem -run=none LeetcodeGolang/Leetcode/0035.Search-Insert-Position -bench=.
cpu: Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
BenchmarkSearchInsertBurst-8 742931880 1.891 ns/op 0 B/op 0 allocs/op
BenchmarkSearchInsertBisection-8 328495410 3.576 ns/op 0 B/op 0 allocs/op
BenchmarkSearchInsertBisection2-8 470675948 2.811 ns/op 0 B/op 0 allocs/op
*/