-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmerge_test.go
45 lines (39 loc) · 1.3 KB
/
merge_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
package merge
import (
"github.com/stretchr/testify/assert"
"github.com/xiaomeng79/go-algorithm/algorithms/sort/testdata"
"github.com/xiaomeng79/go-algorithm/algorithms/sort/utils"
"testing"
)
func TestMergeSort(t *testing.T) {
for _, v := range testdata.Values {
assert.Exactly(t, v.Sort, MergeSort(v.Nosort), "no eq")
}
}
func benchmarkMergeSort(n int, b *testing.B) {
b.StopTimer()
list := utils.GetArrayOfSize(n)
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
//sort(list)
MergeSort(list)
}
}
func BenchmarkMergeSort100(b *testing.B) { benchmarkMergeSort(100, b) }
func BenchmarkMergeSort1000(b *testing.B) { benchmarkMergeSort(1000, b) }
func BenchmarkMergeSort10000(b *testing.B) { benchmarkMergeSort(10000, b) }
func BenchmarkMergeSort100000(b *testing.B) { benchmarkMergeSort(100000, b) }
func benchmarkMergeSort2(n int, b *testing.B) {
b.StopTimer()
list := utils.GetArrayOfSize(n)
b.ReportAllocs()
b.StartTimer()
for i := 0; i < b.N; i++ {
sort(list)
}
}
func BenchmarkMergeSort2_100(b *testing.B) { benchmarkMergeSort2(100, b) }
func BenchmarkMergeSort2_1000(b *testing.B) { benchmarkMergeSort2(1000, b) }
func BenchmarkMergeSort2_10000(b *testing.B) { benchmarkMergeSort2(10000, b) }
func BenchmarkMergeSort2_100000(b *testing.B) { benchmarkMergeSort2(100000, b) }