git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/netmap/bench_test.go (about)

     1  package netmap
     2  
     3  import (
     4  	"testing"
     5  
     6  	cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func BenchmarkNetmap_ContainerNodes(b *testing.B) {
    11  	nodes := []NodeInfo{
    12  		nodeInfoFromAttributes("Country", "Russia", "Order", "1"),
    13  		nodeInfoFromAttributes("Country", "Germany", "Order", "2"),
    14  		nodeInfoFromAttributes("Country", "Russia", "Order", "3"),
    15  		nodeInfoFromAttributes("Country", "France", "Order", "4"),
    16  		nodeInfoFromAttributes("Country", "France", "Order", "5"),
    17  		nodeInfoFromAttributes("Country", "Russia", "Order", "6"),
    18  		nodeInfoFromAttributes("Country", "Russia", "Order", "7"),
    19  		nodeInfoFromAttributes("Country", "Germany", "Order", "8"),
    20  		nodeInfoFromAttributes("Country", "Germany", "Order", "9"),
    21  		nodeInfoFromAttributes("Country", "Russia", "Order", "10"),
    22  		nodeInfoFromAttributes("Country", "China", "Order", "11"),
    23  		nodeInfoFromAttributes("Country", "China", "Order", "12"),
    24  		nodeInfoFromAttributes("Country", "Finland", "Order", "13"),
    25  		nodeInfoFromAttributes("Country", "Finland", "Order", "14"),
    26  		nodeInfoFromAttributes("Country", "España", "Order", "15"),
    27  		nodeInfoFromAttributes("Country", "España", "Order", "16"),
    28  	}
    29  
    30  	var nm NetMap
    31  	nm.SetNodes(nodes)
    32  
    33  	policies := []string{
    34  		`REP 2`,
    35  		`REP 2 IN X CBF 2 SELECT 2 FROM * AS X`,
    36  	}
    37  	cnr := cidtest.ID()
    38  
    39  	pivot := make([]byte, 32)
    40  	cnr.Encode(pivot)
    41  
    42  	for i := range policies {
    43  		b.Run(policies[i], func(b *testing.B) {
    44  			var p PlacementPolicy
    45  			require.NoError(b, p.DecodeString(policies[i]))
    46  
    47  			b.ResetTimer()
    48  			b.ReportAllocs()
    49  
    50  			for range b.N {
    51  				_, err := nm.ContainerNodes(p, pivot)
    52  				if err != nil {
    53  					b.Fatal(err)
    54  				}
    55  			}
    56  		})
    57  	}
    58  }