github.com/enetx/g@v1.0.80/tests/mapord_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 genMO() g.MapOrd[g.String, int] {
    12  	mo := g.NewMapOrd[g.String, int](10000)
    13  	for i := range 10000 {
    14  		mo.Set(g.NewInt(i).ToString(), i)
    15  	}
    16  
    17  	return mo
    18  }
    19  
    20  func BenchmarkMoContains(b *testing.B) {
    21  	mo := genMO()
    22  	b.ResetTimer()
    23  
    24  	for n := 0; n < b.N; n++ {
    25  		_ = mo.Contains("9999")
    26  	}
    27  }
    28  
    29  func BenchmarkMoEq(b *testing.B) {
    30  	mo := genMO()
    31  	mo2 := mo.Clone()
    32  
    33  	b.ResetTimer()
    34  
    35  	for n := 0; n < b.N; n++ {
    36  		_ = mo.Eq(mo2)
    37  	}
    38  }
    39  
    40  func BenchmarkMoGet(b *testing.B) {
    41  	mo := genMO()
    42  	b.ResetTimer()
    43  
    44  	for n := 0; n < b.N; n++ {
    45  		_ = mo.Get("9999")
    46  	}
    47  }