Skip to content

Commit

Permalink
Stablize SkipList benchmark (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
chen3feng committed Aug 17, 2022
1 parent e4443d7 commit f225bbc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ func AverageAs[R, T Numeric](a []T) R {

// Average returns the average value of a.
func Average[T Numeric](a []T) T {
var x T
var i interface{} = x
switch i.(type) {
var zero T // NOTE: convert 0 to interface have no malloc
switch any(zero).(type) {
case int, int8, uint8, int16, uint16, int32, uint32:
return T(AverageAs[int64](a))
case uint64:
Expand Down
1 change: 1 addition & 0 deletions skiplist_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func BenchmarkSkipList_Find(b *testing.B) {

func BenchmarkSkipListString(b *testing.B) {
sl := NewSkipList[string, int]()
sl.rander.Seed(0)
var a []string
for i := 0; i < benchBatchSize; i++ {
a = append(a, strconv.Itoa(benchInitSize+i))
Expand Down
1 change: 1 addition & 0 deletions skiplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestSkipList_Insert_Dup(t *testing.T) {

func newSkipListN(n int) *SkipList[int, int] {
sl := NewSkipList[int, int]()
sl.rander.Seed(0)
for i := 0; i < n; i++ {
sl.Insert(i, i)
}
Expand Down

0 comments on commit f225bbc

Please sign in to comment.