mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 05:37:55 +08:00
40 lines
879 B
Go
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,
|
|
})
|
|
}
|
|
}
|