1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

build: modernize benchmark usage

This commit is contained in:
Nick Craig-Wood
2025-09-14 16:13:42 +01:00
parent d7aa37d263
commit 04d49bf0ea
3 changed files with 6 additions and 6 deletions

View File

@@ -172,8 +172,8 @@ func BenchmarkQuickXorHash(b *testing.B) {
require.NoError(b, err)
require.Equal(b, len(buf), n)
h := New()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
h.Reset()
h.Write(buf)
h.Sum(nil)

View File

@@ -213,7 +213,7 @@ func BenchmarkCheckParents(b *testing.B) {
dt.Add(o)
}
b.StartTimer()
for n := 0; n < b.N; n++ {
for b.Loop() {
dt.CheckParents("")
}
})

View File

@@ -31,7 +31,7 @@ func BenchmarkAllocFree(b *testing.B) {
for _, dirty := range []bool{false, true} {
for size := 4096; size <= 32*1024*1024; size *= 2 {
b.Run(fmt.Sprintf("%dk,dirty=%v", size>>10, dirty), func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
mem := MustAlloc(size)
if dirty {
mem[0] ^= 0xFF
@@ -62,7 +62,7 @@ func BenchmarkAllocFreeWithLotsOfAllocations(b *testing.B) {
for preAllocs := 1; preAllocs <= maxAllocs; preAllocs *= 2 {
allocs := alloc(preAllocs)
b.Run(fmt.Sprintf("%d", preAllocs), func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
mem := MustAlloc(size)
mem[0] ^= 0xFF
MustFree(mem)
@@ -90,7 +90,7 @@ func BenchmarkAllocFreeForLotsOfAllocations(b *testing.B) {
}
for preAllocs := 1; preAllocs <= maxAllocs; preAllocs *= 2 {
b.Run(fmt.Sprintf("%d", preAllocs), func(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
allocs := alloc(preAllocs)
free(allocs)
}