forked from TrueCloudLab/frostfs-node
Evgenii Stratonikov
abbecf49d6
``` name old time/op new time/op delta _addressFromString-8 1.25µs ±30% 1.02µs ± 6% -18.49% (p=0.000 n=9+9) name old alloc/op new alloc/op delta _addressFromString-8 352B ± 0% 256B ± 0% -27.27% (p=0.000 n=9+10) name old allocs/op new allocs/op delta _addressFromString-8 6.00 ± 0% 4.00 ± 0% -33.33% (p=0.000 n=10+10) ``` Also, assure compiler that `s` doesn't escape: Before this commit: ``` ./fstree.go:74:24: leaking param: s ./fstree.go:90:6: moved to heap: addr ``` After this commit: ``` ./fstree.go:74:24: s does not escape ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
30 lines
606 B
Go
30 lines
606 B
Go
package fstree
|
|
|
|
import (
|
|
"testing"
|
|
|
|
oidtest "github.com/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAddressToString(t *testing.T) {
|
|
addr := oidtest.Address()
|
|
s := stringifyAddress(addr)
|
|
actual, err := addressFromString(s)
|
|
require.NoError(t, err)
|
|
require.Equal(t, addr, actual)
|
|
}
|
|
|
|
func Benchmark_addressFromString(b *testing.B) {
|
|
addr := oidtest.Address()
|
|
s := stringifyAddress(addr)
|
|
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := addressFromString(s)
|
|
if err != nil {
|
|
b.Fatalf("benchmark error: %v", err)
|
|
}
|
|
}
|
|
}
|