Skip to content

Commit

Permalink
add String benchmark
Browse files Browse the repository at this point in the history
We call String all over the place so we should make sure it remains fast.
  • Loading branch information
Stebalien committed Apr 20, 2018
1 parent 0783558 commit 93b08a6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,17 @@ func TestFromJson(t *testing.T) {
t.Fatal("json parsing failed")
}
}

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()
}
}

0 comments on commit 93b08a6

Please sign in to comment.