Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions ledger/lruaccts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package ledger

import (
"encoding/binary"
"testing"
"time"

Expand Down Expand Up @@ -195,3 +196,42 @@ func TestLRUAccountsOmittedPendingWrites(t *testing.T) {
require.Equal(t, persistedAccountData{}, acct)
}
}

func BenchmarkLRUAccountsWrite(b *testing.B) {
accounts := generatePersistedAccountData(0, 5000)
fillerAccounts := generatePersistedAccountData(5000, 100000)

baseAccts := make([]lruAccounts, b.N)
for i := 0; i < b.N; i++ {
baseAccts[i].init(logging.TestingLog(b), 10, 5)
Copy link
Contributor

@tsachiherman tsachiherman Jun 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to get realistic timings, you'll need to fill this data structure with dummy data.
Testing the performance against an empty datastructure is less than likly to represent a typical load.

Copy link
Contributor Author

@algonathan algonathan Jun 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.
i've changed the code to generate 5k accounts for the benchmark, and made certain to fill the baseAccts with 95k different persistedAccountData before running the benchmark.
Thanks!

for _, account := range fillerAccounts {
baseAccts[i].write(account)
}
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
baseAcct := baseAccts[i]
for _, account := range accounts {
baseAcct.write(account)
}
}
}

func generatePersistedAccountData(startRound, endRound int) []persistedAccountData {
accounts := make([]persistedAccountData, endRound-startRound)
buffer := make([]byte, 4)

for i := startRound; i < endRound; i++ {
binary.BigEndian.PutUint32(buffer, uint32(i))
digest := crypto.Hash(buffer)

accounts[i-startRound] = persistedAccountData{
addr: basics.Address(digest),
round: basics.Round(i),
rowid: int64(i),
accountData: basics.AccountData{MicroAlgos: basics.MicroAlgos{Raw: uint64(i)}},
}
}
return accounts
}