Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
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
55 changes: 25 additions & 30 deletions benchmarks/checkpointing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,37 @@ import { CheckpointTrie } from '../dist'
const iterations = 500
const samples = 20

const iterTest = async (numOfIter: number): Promise<Array<number>> => {
return new Promise(async (resolve) => {
let vals = [] as any
let keys = [] as any

for (let i = 0; i <= numOfIter; i++) {
vals.push(pseudoRandomBytes(32))
keys.push(pseudoRandomBytes(32))
}

let hrstart = process.hrtime()
let numOfOps = 0
let trie = new CheckpointTrie()

for (let i = 0; i < numOfIter; i++) {
await trie.put(vals[i], keys[i])
trie.checkpoint()
await trie.get(Buffer.from('test'))
numOfOps++
if (numOfOps === numOfIter) {
const hrend = process.hrtime(hrstart)
resolve(hrend)
}
}
})
const iterTest = (numOfIter: number): [number, number] | undefined => {
let vals = [] as any
let keys = [] as any

for (let i = 0; i <= numOfIter; i++) {
vals.push(pseudoRandomBytes(32))
keys.push(pseudoRandomBytes(32))
}

let hrstart = process.hrtime()
let trie = new CheckpointTrie()

for (let i = 0; i < numOfIter; i++) {
trie.put(vals[i], keys[i])
trie.checkpoint()
trie.get(Buffer.from('test'))
}

const hrend = process.hrtime(hrstart)
return hrend
}

const go = async () => {
const go = () => {
let i = 0
let avg = [0, 0]

while (i <= samples) {
const hrend = await iterTest(iterations)
avg[0] += hrend[0]
avg[1] += hrend[1]
// console.log('benchmarks/checkpointing.ts | execution time: %ds %dms', hrend[0], (hrend[1] / 1000000).toFixed(3))
const hrend = iterTest(iterations)
avg[0] += hrend![0]
avg[1] += hrend![1]
// console.log('benchmarks/checkpointing.ts | execution time: %ds %dms', hrend![0], (hrend![1] / 1000000).toFixed(3))
i++
}
console.log(
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ERA_SIZE = 1000
const trie = new BaseTrie()
let seed = Buffer.alloc(32).fill(0)

const run = async (): Promise<void> => {
const run = () => {
let i = 0
while (i <= ROUNDS) {
seed = keccak256(seed)
Expand All @@ -22,24 +22,24 @@ const run = async (): Promise<void> => {
}

if (SYMMETRIC) {
await trie.put(seed, seed)
trie.put(seed, seed)
genRoot()
} else {
const val = keccak256(seed)
await trie.put(seed, val)
trie.put(seed, val)
genRoot()
}

i++
}
}

const go = async () => {
const go = () => {
const testName = `benchmarks/random.ts | rounds: ${ROUNDS}, ERA_SIZE: ${ERA_SIZE}, ${
SYMMETRIC ? 'sys' : 'rand'
}`
console.time(testName)
await run()
run()
console.timeEnd(testName)
}

Expand Down
Loading