Skip to content

Commit

Permalink
adding mysort function with a benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
ericox committed Jul 1, 2015
1 parent 95e0137 commit daea568
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions benchdb/benchdb_test.go
@@ -0,0 +1,29 @@
package benchdb

import (
"math/rand"
"sort"
"testing"
)

func mySort(data sort.Interface, a, b int) {
// Insertion sort borrowed from the std library.
for i := a + 1; i < b; i++ {
for j := i; j > a && data.Less(j, j-1); j-- {
data.Swap(j, j-1)
}
}
}

func BenchmarkMySort1K(b *testing.B) {
b.StopTimer()
for i := 0; i < b.N; i++ {
data := make([]int, 1000)
for i := 0; i < len(data); i++ {
data[i] = rand.Int()
}
b.StartTimer()
mySort(sort.IntSlice(data), 0, len(data))
b.StopTimer()
}
}

0 comments on commit daea568

Please sign in to comment.