Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge 1381cf1 into 7583aa9
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Apr 23, 2020
2 parents 7583aa9 + 1381cf1 commit a6f42f6
Show file tree
Hide file tree
Showing 27 changed files with 967 additions and 1,380 deletions.
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

0 comments on commit a6f42f6

Please sign in to comment.