frostfs-sdk-go/netmap/bench_test.go
Ekaterina Lebedeva 46ee543899 [#265] go.mod: Use range over int
Since Go 1.22 a `for` statement with a `range` clause is able
to iterate through integer values from zero to an upper limit.

gopatch script:
@@
var i, e expression
@@
-for i := 0; i <= e - 1; i++ {
+for i := range e {
    ...
}

@@
var i, e expression
@@
-for i := 0; i <= e; i++ {
+for i := range e + 1 {
    ...
}

@@
var i, e expression
@@
-for i := 0; i < e; i++ {
+for i := range e {
    ...
}

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
2024-09-04 12:37:46 +03:00

58 lines
1.7 KiB
Go

package netmap
import (
"testing"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
"github.com/stretchr/testify/require"
)
func BenchmarkNetmap_ContainerNodes(b *testing.B) {
nodes := []NodeInfo{
nodeInfoFromAttributes("Country", "Russia", "Order", "1"),
nodeInfoFromAttributes("Country", "Germany", "Order", "2"),
nodeInfoFromAttributes("Country", "Russia", "Order", "3"),
nodeInfoFromAttributes("Country", "France", "Order", "4"),
nodeInfoFromAttributes("Country", "France", "Order", "5"),
nodeInfoFromAttributes("Country", "Russia", "Order", "6"),
nodeInfoFromAttributes("Country", "Russia", "Order", "7"),
nodeInfoFromAttributes("Country", "Germany", "Order", "8"),
nodeInfoFromAttributes("Country", "Germany", "Order", "9"),
nodeInfoFromAttributes("Country", "Russia", "Order", "10"),
nodeInfoFromAttributes("Country", "China", "Order", "11"),
nodeInfoFromAttributes("Country", "China", "Order", "12"),
nodeInfoFromAttributes("Country", "Finland", "Order", "13"),
nodeInfoFromAttributes("Country", "Finland", "Order", "14"),
nodeInfoFromAttributes("Country", "España", "Order", "15"),
nodeInfoFromAttributes("Country", "España", "Order", "16"),
}
var nm NetMap
nm.SetNodes(nodes)
policies := []string{
`REP 2`,
`REP 2 IN X CBF 2 SELECT 2 FROM * AS X`,
}
cnr := cidtest.ID()
pivot := make([]byte, 32)
cnr.Encode(pivot)
for i := range policies {
b.Run(policies[i], func(b *testing.B) {
var p PlacementPolicy
require.NoError(b, p.DecodeString(policies[i]))
b.ResetTimer()
b.ReportAllocs()
for range b.N {
_, err := nm.ContainerNodes(p, pivot)
if err != nil {
b.Fatal(err)
}
}
})
}
}