Skip to content

Commit 55a347c

Browse files
authored
test: use newer Loop vs increment counter (#458)
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
1 parent 9eaa694 commit 55a347c

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

internal/miner/miner_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
// BenchmarkRandomNonce tests the performance of generating a completely new random nonce
2626
// each iteration
2727
func BenchmarkRandomNonce(b *testing.B) {
28-
for i := 0; i < b.N; i++ {
28+
for b.Loop() {
2929
randomNonce()
3030
}
3131
}
@@ -34,7 +34,7 @@ func BenchmarkRandomNonce(b *testing.B) {
3434
// and incrementing each byte 255 times
3535
func BenchmarkRandomNonceAndIncrement(b *testing.B) {
3636
var tmpNonce [16]byte
37-
for i := 0; i < b.N; i++ {
37+
for i := 0; b.Loop(); i++ {
3838
if i%256 == 0 {
3939
// Generate random nonce for first and every 256 iterations
4040
tmpNonce = randomNonce()
@@ -51,7 +51,7 @@ func BenchmarkRandomNonceAndIncrement(b *testing.B) {
5151
func BenchmarkSha256Builtin(b *testing.B) {
5252
var hasher hash.Hash
5353
tmpNonce := randomNonce()
54-
for i := 0; i < b.N; i++ {
54+
for b.Loop() {
5555
hasher = sha256.New()
5656
hasher.Write(tmpNonce[:])
5757
hasher.Sum(nil)
@@ -62,7 +62,7 @@ func BenchmarkSha256Builtin(b *testing.B) {
6262
func BenchmarkSha256Simd(b *testing.B) {
6363
var hasher hash.Hash
6464
tmpNonce := randomNonce()
65-
for i := 0; i < b.N; i++ {
65+
for b.Loop() {
6666
hasher = sha256_simd.New()
6767
hasher.Write(tmpNonce[:])
6868
hasher.Sum(nil)
@@ -81,7 +81,7 @@ func BenchmarkTargetStateCborMarshal(b *testing.B) {
8181
LeadingZeros: 4,
8282
DifficultyNumber: 65535,
8383
}
84-
for i := 0; i < b.N; i++ {
84+
for b.Loop() {
8585
_, _ = tmpState.MarshalCBOR()
8686
}
8787
}
@@ -98,7 +98,7 @@ func BenchmarkTargetStateCborMarshalNoCache(b *testing.B) {
9898
LeadingZeros: 4,
9999
DifficultyNumber: 65535,
100100
}
101-
for i := 0; i < b.N; i++ {
101+
for b.Loop() {
102102
_, _ = tmpState.MarshalCBOR()
103103
// Wipe out CBOR cache
104104
tmpState.cachedCbor = nil

0 commit comments

Comments
 (0)