~telemachus/algorithms

algorithms/benchmark_quickselect_test.go -rw-r--r-- 2.2 KiB
c4396785Peter Aronoff Update for golangci-lint 9 months ago
                                                                                
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package algorithms_test

import (
	"testing"

	"git.sr.ht/~telemachus/algorithms"
)

func BenchmarkLomutoQuickselectShuffledSlice(b *testing.B) {
	xs := shuffledSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectL(xs, 0, len(xs)-1, 3567)
	}
}

func BenchmarkHoareQuickselectShuffledSlice(b *testing.B) {
	xs := shuffledSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectH(xs, 0, len(xs)-1, 3567)
	}
}

func BenchmarkYourBasicQuickselectShuffledSlice(b *testing.B) {
	xs := shuffledSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectYB(xs, 3567)
	}
}

func BenchmarkLomutoQuickselectEqualSlice(b *testing.B) {
	xs := equalSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectL(xs, 0, len(xs)-1, 3567)
	}
}

func BenchmarkHoareQuickselectEqualSlice(b *testing.B) {
	xs := equalSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectH(xs, 0, len(xs)-1, 3567)
	}
}

func BenchmarkYourBasicQuickselectEqualSlice(b *testing.B) {
	xs := equalSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectYB(xs, 3567)
	}
}

func BenchmarkLomutoQuickselectInOrderSlice(b *testing.B) {
	xs := inOrderSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectL(xs, 0, len(xs)-1, 3567)
	}
}

func BenchmarkHoareQuickselectInOrderSlice(b *testing.B) {
	xs := inOrderSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectH(xs, 0, len(xs)-1, 3567)
	}
}

func BenchmarkYourBasicQuickselectInOrderSlice(b *testing.B) {
	xs := inOrderSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectYB(xs, 3567)
	}
}

func BenchmarkLomutoQuickselectReversedSlice(b *testing.B) {
	xs := reversedSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectL(xs, 0, len(xs)-1, 3567)
	}
}

func BenchmarkHoareQuickselectReversedSlice(b *testing.B) {
	xs := reversedSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectH(xs, 0, len(xs)-1, 3567)
	}
}

func BenchmarkYourBasicQuickselectReversedSlice(b *testing.B) {
	xs := reversedSlice()
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		algorithms.QuickselectYB(xs, 3567)
	}
}