gf/container/garray/garray_z_bench_any_test.go
2021-08-06 12:08:49 +08:00

40 lines
879 B
Go

// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package garray_test
import (
"github.com/gogf/gf/container/garray"
"testing"
)
type anySortedArrayItem struct {
priority int64
value interface{}
}
var (
anyArray = garray.NewArray()
anySortedArray = garray.NewSortedArray(func(a, b interface{}) int {
return int(a.(anySortedArrayItem).priority - b.(anySortedArrayItem).priority)
})
)
func Benchmark_AnyArray_Add(b *testing.B) {
for i := 0; i < b.N; i++ {
anyArray.Append(i)
}
}
func Benchmark_AnySortedArray_Add(b *testing.B) {
for i := 0; i < b.N; i++ {
anySortedArray.Add(anySortedArrayItem{
priority: int64(i),
value: i,
})
}
}