MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / benchmarkFramework

Function benchmarkFramework

sort/sorts_test.go:207–242  ·  view source on GitHub ↗

END TESTS

(b *testing.B, f func(arr []int) []int)

Source from the content-addressed store, hash-verified

205// END TESTS
206
207func benchmarkFramework(b *testing.B, f func(arr []int) []int) {
208 var sortTests = []struct {
209 input []int
210 expected []int
211 name string
212 }{
213 //Sorted slice
214 {[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
215 []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, "Sorted Unsigned"},
216 //Reversed slice
217 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
218 []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, "Reversed Unsigned"},
219 //Sorted slice
220 {[]int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
221 []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, "Sorted Signed"},
222 //Reversed slice
223 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10},
224 []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, "Reversed Signed"},
225 //Reversed slice, even length
226 {[]int{10, 9, 8, 7, 6, 5, 4, 3, 2, 1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10},
227 []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, "Reversed Signed #2"},
228 //Random order with repetitions
229 {[]int{-5, 7, 4, -2, 6, 5, 8, 3, 2, -7, -1, 0, -3, 9, -6, -4, 10, 9, 1, -8, -9, -10},
230 []int{-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 10}, "Random order Signed"},
231 //Empty slice
232 {[]int{}, []int{}, "Empty"},
233 //Single-entry slice
234 {[]int{1}, []int{1}, "Singleton"},
235 }
236 b.ResetTimer()
237 for i := 0; i < b.N; i++ {
238 for _, test := range sortTests {
239 f(test.input)
240 }
241 }
242}
243
244//BEGIN BENCHMARKS
245

Callers 15

BenchmarkBinaryInsertionFunction · 0.85
BenchmarkBubbleFunction · 0.85
BenchmarkBogoFunction · 0.85
BenchmarkBucketSortFunction · 0.85
BenchmarkCocktailSortFunction · 0.85
BenchmarkExchangeFunction · 0.85
BenchmarkInsertionFunction · 0.85
BenchmarkMergeFunction · 0.85
BenchmarkMergeIterFunction · 0.85
BenchmarkMergeParallelFunction · 0.85
BenchmarkHeapFunction · 0.85
BenchmarkCountFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected