github.com/zhongdalu/gf@v1.0.0/g/container/garray/garray_z_bench_test.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). 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/zhongdalu/gf. 6 7 // go test *.go -bench=".*" -benchmem 8 9 package garray_test 10 11 import ( 12 "testing" 13 14 "github.com/zhongdalu/gf/g/container/garray" 15 ) 16 17 var ( 18 sortedIntArray = garray.NewSortedIntArray() 19 ) 20 21 func BenchmarkSortedIntArray_Add(b *testing.B) { 22 b.N = 1000 23 for i := 0; i < b.N; i++ { 24 sortedIntArray.Add(i) 25 } 26 } 27 28 func BenchmarkSortedIntArray_Search(b *testing.B) { 29 for i := 0; i < b.N; i++ { 30 sortedIntArray.Search(i) 31 } 32 } 33 34 func BenchmarkSortedIntArray_PopLeft(b *testing.B) { 35 for i := 0; i < b.N; i++ { 36 sortedIntArray.PopLeft() 37 } 38 } 39 40 func BenchmarkSortedIntArray_PopRight(b *testing.B) { 41 for i := 0; i < b.N; i++ { 42 sortedIntArray.PopLeft() 43 } 44 }