From d6e0b4e5a7b771087a8c56e21c0a2c5a15715571 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 20 Apr 2018 10:30:12 +0900 Subject: [PATCH] add String benchmark We call String all over the place so we should make sure it remains fast. --- cid_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cid_test.go b/cid_test.go index ed690d8..1540cf4 100644 --- a/cid_test.go +++ b/cid_test.go @@ -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() + } +}