Skip to content

Commit

Permalink
Rename vars from xxxSize to xxxCount if appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Feb 3, 2025
1 parent 4603919 commit d7ac755
Show file tree
Hide file tree
Showing 6 changed files with 1,786 additions and 1,786 deletions.
96 changes: 48 additions & 48 deletions array_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ var noopStorable Storable

func BenchmarkArrayGet100x(b *testing.B) {
benchmarks := []struct {
name string
initialArraySize int
numberOfOps int
long bool
name string
initialArrayCount int
numberOfOps int
long bool
}{
{"10", 10, 100, false},
{"1000", 1000, 100, false},
Expand All @@ -47,17 +47,17 @@ func BenchmarkArrayGet100x(b *testing.B) {
if bm.long && testing.Short() {
b.Skipf("Skipping %s in short mode", bm.name)
}
benchmarkArrayGet(b, bm.initialArraySize, bm.numberOfOps)
benchmarkArrayGet(b, bm.initialArrayCount, bm.numberOfOps)
})
}
}

func BenchmarkArrayInsert100x(b *testing.B) {
benchmarks := []struct {
name string
initialArraySize int
numberOfOps int
long bool
name string
initialArrayCount int
numberOfOps int
long bool
}{
{"10", 10, 100, false},
{"1000", 1000, 100, false},
Expand All @@ -71,17 +71,17 @@ func BenchmarkArrayInsert100x(b *testing.B) {
if bm.long && testing.Short() {
b.Skipf("Skipping %s in short mode", bm.name)
}
benchmarkArrayInsert(b, bm.initialArraySize, bm.numberOfOps)
benchmarkArrayInsert(b, bm.initialArrayCount, bm.numberOfOps)
})
}
}

func BenchmarkArrayRemove100x(b *testing.B) {
benchmarks := []struct {
name string
initialArraySize int
numberOfOps int
long bool
name string
initialArrayCount int
numberOfOps int
long bool
}{
{"100", 100, 100, false},
{"1000", 1000, 100, false},
Expand All @@ -95,17 +95,17 @@ func BenchmarkArrayRemove100x(b *testing.B) {
if bm.long && testing.Short() {
b.Skipf("Skipping %s in short mode", bm.name)
}
benchmarkArrayRemove(b, bm.initialArraySize, bm.numberOfOps)
benchmarkArrayRemove(b, bm.initialArrayCount, bm.numberOfOps)
})
}
}

// BenchmarkArrayRemoveAll benchmarks removing all elements in a loop.
func BenchmarkArrayRemoveAll(b *testing.B) {
benchmarks := []struct {
name string
initialArraySize int
long bool
name string
initialArrayCount int
long bool
}{
{"100", 100, false},
{"1000", 1000, false},
Expand All @@ -117,17 +117,17 @@ func BenchmarkArrayRemoveAll(b *testing.B) {
if bm.long && testing.Short() {
b.Skipf("Skipping %s in short mode", bm.name)
}
benchmarkArrayRemoveAll(b, bm.initialArraySize)
benchmarkArrayRemoveAll(b, bm.initialArrayCount)
})
}
}

// BenchmarkArrayPopIterate benchmarks removing all elements using PopIterate.
func BenchmarkArrayPopIterate(b *testing.B) {
benchmarks := []struct {
name string
initialArraySize int
long bool
name string
initialArrayCount int
long bool
}{
{"100", 100, false},
{"1000", 1000, false},
Expand All @@ -139,16 +139,16 @@ func BenchmarkArrayPopIterate(b *testing.B) {
if bm.long && testing.Short() {
b.Skipf("Skipping %s in short mode", bm.name)
}
benchmarkArrayPopIterate(b, bm.initialArraySize)
benchmarkArrayPopIterate(b, bm.initialArrayCount)
})
}
}

func BenchmarkNewArrayFromAppend(b *testing.B) {
benchmarks := []struct {
name string
initialArraySize int
long bool
name string
initialArrayCount int
long bool
}{
{"100", 100, false},
{"1000", 1000, false},
Expand All @@ -160,16 +160,16 @@ func BenchmarkNewArrayFromAppend(b *testing.B) {
if bm.long && testing.Short() {
b.Skipf("Skipping %s in short mode", bm.name)
}
benchmarkNewArrayFromAppend(b, bm.initialArraySize)
benchmarkNewArrayFromAppend(b, bm.initialArrayCount)
})
}
}

func BenchmarkNewArrayFromBatchData(b *testing.B) {
benchmarks := []struct {
name string
initialArraySize int
long bool
name string
initialArrayCount int
long bool
}{
{"100", 100, false},
{"1000", 1000, false},
Expand All @@ -181,12 +181,12 @@ func BenchmarkNewArrayFromBatchData(b *testing.B) {
if bm.long && testing.Short() {
b.Skipf("Skipping %s in short mode", bm.name)
}
benchmarkNewArrayFromBatchData(b, bm.initialArraySize)
benchmarkNewArrayFromBatchData(b, bm.initialArrayCount)
})
}
}

func setupArray(b *testing.B, r *rand.Rand, storage *PersistentSlabStorage, initialArraySize int) *Array {
func setupArray(b *testing.B, r *rand.Rand, storage *PersistentSlabStorage, initialArrayCount int) *Array {

address := Address{1, 2, 3, 4, 5, 6, 7, 8}

Expand All @@ -195,7 +195,7 @@ func setupArray(b *testing.B, r *rand.Rand, storage *PersistentSlabStorage, init
array, err := NewArray(storage, address, typeInfo)
require.NoError(b, err)

for i := 0; i < initialArraySize; i++ {
for i := 0; i < initialArrayCount; i++ {
v := RandomValue(r)
err := array.Append(v)
require.NoError(b, err)
Expand All @@ -214,15 +214,15 @@ func setupArray(b *testing.B, r *rand.Rand, storage *PersistentSlabStorage, init
return newArray
}

func benchmarkArrayGet(b *testing.B, initialArraySize, numberOfOps int) {
func benchmarkArrayGet(b *testing.B, initialArrayCount, numberOfOps int) {

b.StopTimer()

r := newRand(b)

storage := newTestPersistentStorage(b)

array := setupArray(b, r, storage, initialArraySize)
array := setupArray(b, r, storage, initialArrayCount)

var value Value

Expand All @@ -238,7 +238,7 @@ func benchmarkArrayGet(b *testing.B, initialArraySize, numberOfOps int) {
noopValue = value
}

func benchmarkArrayInsert(b *testing.B, initialArraySize, numberOfOps int) {
func benchmarkArrayInsert(b *testing.B, initialArrayCount, numberOfOps int) {

b.StopTimer()

Expand All @@ -250,7 +250,7 @@ func benchmarkArrayInsert(b *testing.B, initialArraySize, numberOfOps int) {

b.StopTimer()

array := setupArray(b, r, storage, initialArraySize)
array := setupArray(b, r, storage, initialArrayCount)

b.StartTimer()

Expand All @@ -262,7 +262,7 @@ func benchmarkArrayInsert(b *testing.B, initialArraySize, numberOfOps int) {
}
}

func benchmarkArrayRemove(b *testing.B, initialArraySize, numberOfOps int) {
func benchmarkArrayRemove(b *testing.B, initialArrayCount, numberOfOps int) {

b.StopTimer()

Expand All @@ -274,7 +274,7 @@ func benchmarkArrayRemove(b *testing.B, initialArraySize, numberOfOps int) {

b.StopTimer()

array := setupArray(b, r, storage, initialArraySize)
array := setupArray(b, r, storage, initialArrayCount)

b.StartTimer()

Expand All @@ -285,7 +285,7 @@ func benchmarkArrayRemove(b *testing.B, initialArraySize, numberOfOps int) {
}
}

func benchmarkArrayRemoveAll(b *testing.B, initialArraySize int) {
func benchmarkArrayRemoveAll(b *testing.B, initialArrayCount int) {

b.StopTimer()

Expand All @@ -299,19 +299,19 @@ func benchmarkArrayRemoveAll(b *testing.B, initialArraySize int) {

b.StopTimer()

array := setupArray(b, r, storage, initialArraySize)
array := setupArray(b, r, storage, initialArrayCount)

b.StartTimer()

for i := initialArraySize - 1; i >= 0; i-- {
for i := initialArrayCount - 1; i >= 0; i-- {
storable, _ = array.Remove(uint64(i))
}
}

noopStorable = storable
}

func benchmarkArrayPopIterate(b *testing.B, initialArraySize int) {
func benchmarkArrayPopIterate(b *testing.B, initialArrayCount int) {

b.StopTimer()

Expand All @@ -325,7 +325,7 @@ func benchmarkArrayPopIterate(b *testing.B, initialArraySize int) {

b.StopTimer()

array := setupArray(b, r, storage, initialArraySize)
array := setupArray(b, r, storage, initialArrayCount)

b.StartTimer()

Expand All @@ -340,15 +340,15 @@ func benchmarkArrayPopIterate(b *testing.B, initialArraySize int) {
noopStorable = storable
}

func benchmarkNewArrayFromAppend(b *testing.B, initialArraySize int) {
func benchmarkNewArrayFromAppend(b *testing.B, initialArrayCount int) {

b.StopTimer()

r := newRand(b)

storage := newTestPersistentStorage(b)

array := setupArray(b, r, storage, initialArraySize)
array := setupArray(b, r, storage, initialArrayCount)

b.StartTimer()

Expand All @@ -366,15 +366,15 @@ func benchmarkNewArrayFromAppend(b *testing.B, initialArraySize int) {
}
}

func benchmarkNewArrayFromBatchData(b *testing.B, initialArraySize int) {
func benchmarkNewArrayFromBatchData(b *testing.B, initialArrayCount int) {

b.StopTimer()

r := newRand(b)

storage := newTestPersistentStorage(b)

array := setupArray(b, r, storage, initialArraySize)
array := setupArray(b, r, storage, initialArrayCount)

b.StartTimer()

Expand Down
8 changes: 4 additions & 4 deletions array_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func RandomValue(r *rand.Rand) Value {
}

// BenchmarkArray benchmarks the performance of the atree array
func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
func benchmarkArray(b *testing.B, initialArrayCount, numberOfElements int) {

r := newRand(b)

Expand All @@ -86,7 +86,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
var totalLookupTime time.Duration

// setup
for i := 0; i < initialArraySize; i++ {
for i := 0; i < initialArrayCount; i++ {
v := RandomValue(r)
storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
require.NoError(b, err)
Expand Down Expand Up @@ -197,7 +197,7 @@ func benchmarkArray(b *testing.B, initialArraySize, numberOfElements int) {
func BenchmarkLArrayMemoryImpact(b *testing.B) { benchmarkLongTermImpactOnMemory(b, 10_000, 1000_000) }

// BenchmarkArray benchmarks the performance of the atree array
func benchmarkLongTermImpactOnMemory(b *testing.B, initialArraySize, numberOfOps int) {
func benchmarkLongTermImpactOnMemory(b *testing.B, initialArrayCount, numberOfOps int) {

r := newRand(b)

Expand All @@ -214,7 +214,7 @@ func benchmarkLongTermImpactOnMemory(b *testing.B, initialArraySize, numberOfOps
var totalRawDataSize uint32

// setup
for i := 0; i < initialArraySize; i++ {
for i := 0; i < initialArrayCount; i++ {
v := RandomValue(r)

storable, err := v.Storable(storage, array.Address(), MaxInlineArrayElementSize())
Expand Down
Loading

0 comments on commit d7ac755

Please sign in to comment.