github.com/enetx/g@v1.0.80/tests/slice_append_benchmark_test.go (about)

     1  package g_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/enetx/g"
     7  )
     8  
     9  // go test -bench=. -benchmem -count=4
    10  
    11  func BenchmarkAppendInPlace(b *testing.B) {
    12  	b.ResetTimer()
    13  
    14  	slice := g.NewSlice[g.String]()
    15  
    16  	for i := range 10000000 {
    17  		slice = slice.Append(g.NewInt(i).ToString())
    18  	}
    19  }
    20  
    21  func BenchmarkAppend(b *testing.B) {
    22  	b.ResetTimer()
    23  
    24  	slice := g.NewSlice[g.String]()
    25  
    26  	for i := range 10000000 {
    27  		slice.AppendInPlace(g.NewInt(i).ToString())
    28  	}
    29  }