Hacker News new | ask | show | jobs
by jossctz 3021 days ago
Note that you can also get the number of bytes processed per second by calling the SetBytes method. This is very useful on some bench (hashing, base64, ...):

  func benchmarkHash(b *testing.B, h hash.Hash) {
  	data := make([]byte, 1024)
  	rand.Read(data)  
  
  	b.ResetTimer()
  	b.SetBytes(len(data))
  	for n := 0; n < b.N; n++ {
  		h.Write(data)
  		h.Sum(nil)
  	}
  }