github.com/koko1123/flow-go-1@v0.29.6/model/flow/ledger_test.go (about) 1 package flow 2 3 import ( 4 "encoding/hex" 5 "fmt" 6 7 "testing" 8 ) 9 10 // this benchmark can run with this command: 11 // go test -run=String -bench=. 12 13 // this is to prevent lint errors 14 var length int 15 16 func BenchmarkString(b *testing.B) { 17 18 var r = RegisterID{ 19 Owner: "theowner", 20 Key: "123412341234", 21 } 22 23 ownerLen := len(r.Owner) 24 25 requiredLen := ((ownerLen + len(r.Key)) * 2) + 1 26 27 arr := make([]byte, requiredLen) 28 29 hex.Encode(arr, []byte(r.Owner)) 30 31 arr[2*ownerLen] = byte('/') 32 33 hex.Encode(arr[(2*ownerLen)+1:], []byte(r.Key)) 34 35 s := string(arr) 36 length = len(s) 37 } 38 39 func BenchmarkOriginalString(b *testing.B) { 40 41 var r = RegisterID{ 42 Owner: "theowner", 43 Key: "123412341234", 44 } 45 46 ret := fmt.Sprintf("%x/%x", r.Owner, r.Key) 47 48 length = len(ret) 49 }