github.com/wangyougui/gf/v2@v2.6.5/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/wangyougui/gf.
     6  
     7  package garray_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/wangyougui/gf/v2/container/garray"
    13  )
    14  
    15  type anySortedArrayItem struct {
    16  	priority int64
    17  	value    interface{}
    18  }
    19  
    20  var (
    21  	anyArray       = garray.NewArray()
    22  	anySortedArray = garray.NewSortedArray(func(a, b interface{}) int {
    23  		return int(a.(anySortedArrayItem).priority - b.(anySortedArrayItem).priority)
    24  	})
    25  )
    26  
    27  func Benchmark_AnyArray_Add(b *testing.B) {
    28  	for i := 0; i < b.N; i++ {
    29  		anyArray.Append(i)
    30  	}
    31  }
    32  
    33  func Benchmark_AnySortedArray_Add(b *testing.B) {
    34  	for i := 0; i < b.N; i++ {
    35  		anySortedArray.Add(anySortedArrayItem{
    36  			priority: int64(i),
    37  			value:    i,
    38  		})
    39  	}
    40  }