add String benchmark

We call String all over the place so we should make sure it remains fast.
This commit is contained in:
Steven Allen
2018-04-20 10:30:12 +09:00
parent 5eff744da0
commit d6e0b4e5a7

View File

@@ -414,3 +414,17 @@ func TestJsonRoundTrip(t *testing.T) {
t.Fatal("cids not equal for Cid")
}
}
func BenchmarkStringV1(b *testing.B) {
data := []byte("this is some test content")
hash, _ := mh.Sum(data, mh.SHA2_256, -1)
cid := NewCidV1(Raw, hash)
b.ResetTimer()
count := 0
for i := 0; i < b.N; i++ {
count += len(cid.String())
}
if count != 49*b.N {
b.FailNow()
}
}