github.com/gogf/gf@v1.16.9/container/garray/garray_z_bench_any_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package garray_test 8 9 import ( 10 "github.com/gogf/gf/container/garray" 11 "testing" 12 ) 13 14 type anySortedArrayItem struct { 15 priority int64 16 value interface{} 17 } 18 19 var ( 20 anyArray = garray.NewArray() 21 anySortedArray = garray.NewSortedArray(func(a, b interface{}) int { 22 return int(a.(anySortedArrayItem).priority - b.(anySortedArrayItem).priority) 23 }) 24 ) 25 26 func Benchmark_AnyArray_Add(b *testing.B) { 27 for i := 0; i < b.N; i++ { 28 anyArray.Append(i) 29 } 30 } 31 32 func Benchmark_AnySortedArray_Add(b *testing.B) { 33 for i := 0; i < b.N; i++ { 34 anySortedArray.Add(anySortedArrayItem{ 35 priority: int64(i), 36 value: i, 37 }) 38 } 39 }