github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/collection/mutable/vector/test/vector_benchmark_test.go (about)

     1  package vector
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/m4gshm/gollections/collection/mutable/vector"
     7  	"github.com/m4gshm/gollections/slice/range_"
     8  )
     9  
    10  var (
    11  	max    = 100000
    12  	values = range_.Closed(1, max)
    13  )
    14  
    15  func Benchmark_Vector_Add(b *testing.B) {
    16  	v := vector.NewCap[int](max)
    17  	b.ResetTimer()
    18  	for i := 0; i < b.N; i++ {
    19  		v.Add(values...)
    20  	}
    21  	b.StopTimer()
    22  	_ = v
    23  }
    24  
    25  func Benchmark_Vector_Add_ByOne(b *testing.B) {
    26  	v := vector.NewCap[int](max)
    27  	b.ResetTimer()
    28  	for i := 0; i < b.N; i++ {
    29  		for _, i := range values {
    30  			v.Add(i)
    31  		}
    32  	}
    33  	b.StopTimer()
    34  	_ = v
    35  }
    36  
    37  func Benchmark_Vector_Add_All(b *testing.B) {
    38  	v := vector.NewCap[int](max)
    39  	b.ResetTimer()
    40  	for i := 0; i < b.N; i++ {
    41  		v.Add(values...)
    42  	}
    43  	b.StopTimer()
    44  	_ = v
    45  }