This repository was archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Promisify rest of library #107
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,52 @@ | ||
| import * as async from 'async' | ||
| import * as crypto from 'crypto' | ||
| const Trie = require('../dist/index.js').CheckpointTrie | ||
| import { pseudoRandomBytes } from 'crypto' | ||
| import { CheckpointTrie } from '../dist' | ||
|
|
||
| let iterations = 500 | ||
| let samples = 20 | ||
| let i = 0 | ||
| const iterations = 500 | ||
| const samples = 20 | ||
|
|
||
| function iterTest(numOfIter: number, cb: Function) { | ||
| let vals = [] as any | ||
| let keys = [] as any | ||
| const iterTest = async (numOfIter: number): Promise<Array<number>> => { | ||
| return new Promise(async (resolve) => { | ||
| let vals = [] as any | ||
| let keys = [] as any | ||
|
|
||
| for (i = 0; i <= numOfIter; i++) { | ||
| vals.push(crypto.pseudoRandomBytes(32)) | ||
| keys.push(crypto.pseudoRandomBytes(32)) | ||
| } | ||
| 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 Trie() | ||
| let hrstart = process.hrtime() | ||
| let numOfOps = 0 | ||
| let trie = new CheckpointTrie() | ||
|
|
||
| for (i = 0; i < numOfIter; i++) { | ||
| trie.put(vals[i], keys[i], function () { | ||
| for (let i = 0; i < numOfIter; i++) { | ||
| await trie.put(vals[i], keys[i]) | ||
| trie.checkpoint() | ||
| trie.get(Buffer.from('test'), function () { | ||
| numOfOps++ | ||
| if (numOfOps === numOfIter) { | ||
| const hrend = process.hrtime(hrstart) | ||
| cb(hrend) | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
| await trie.get(Buffer.from('test')) | ||
| numOfOps++ | ||
| if (numOfOps === numOfIter) { | ||
| const hrend = process.hrtime(hrstart) | ||
| resolve(hrend) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| i = 0 | ||
| let avg = [0, 0] | ||
| const go = async () => { | ||
| let i = 0 | ||
| let avg = [0, 0] | ||
|
|
||
| async.whilst( | ||
| function () { | ||
| 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)) | ||
| i++ | ||
| return i <= samples | ||
| }, | ||
| function (done) { | ||
| iterTest(iterations, function (hrend: Array<number>) { | ||
| avg[0] += hrend[0] | ||
| avg[1] += hrend[1] | ||
|
|
||
| console.info('Execution time (hr): %ds %dms', hrend[0], hrend[1] / 1000000) | ||
| done() | ||
| }) | ||
| }, | ||
| function () { | ||
| console.info( | ||
| 'Average Execution time (hr): %ds %dms', | ||
| avg[0] / samples, | ||
| avg[1] / 1000000 / samples, | ||
| ) | ||
| }, | ||
| ) | ||
| } | ||
| console.log( | ||
| 'benchmarks/checkpointing.ts | average execution time: %ds %dms', | ||
| avg[0] / samples, | ||
| (avg[1] / 1000000 / samples).toFixed(3), | ||
| ) | ||
| } | ||
|
|
||
| go() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,46 @@ | ||
| // https://github.com/ethereum/wiki/wiki/Benchmarks | ||
| 'use strict' | ||
| import * as async from 'async' | ||
| import * as ethUtil from 'ethereumjs-util' | ||
| const Trie = require('../dist/index.js').BaseTrie | ||
| import { keccak256 } from 'ethereumjs-util' | ||
| import { BaseTrie } from '../dist' | ||
|
|
||
| const ROUNDS = 1000 | ||
| const SYMMETRIC = true | ||
| const ERA_SIZE = 1000 | ||
|
|
||
| let trie = new Trie() | ||
| const trie = new BaseTrie() | ||
| let seed = Buffer.alloc(32).fill(0) | ||
|
|
||
| let testName = 'rounds ' + ROUNDS + ' ' + ERA_SIZE + ' ' + SYMMETRIC ? 'sys' : 'rand' | ||
| console.time(testName) | ||
| run(() => { | ||
| console.timeEnd(testName) | ||
| }) | ||
|
|
||
| function run(cb: any) { | ||
| const run = async (): Promise<void> => { | ||
| let i = 0 | ||
| async.whilst( | ||
| () => { | ||
| i++ | ||
| return i <= ROUNDS | ||
| }, | ||
| function (done) { | ||
| seed = ethUtil.keccak256(seed) | ||
| if (SYMMETRIC) { | ||
| trie.put(seed, seed, genRoot) | ||
| } else { | ||
| let val = ethUtil.keccak256(seed) | ||
| trie.put(seed, val, genRoot) | ||
| } | ||
| while (i <= ROUNDS) { | ||
| seed = keccak256(seed) | ||
|
|
||
| function genRoot() { | ||
| if (i % ERA_SIZE === 0) { | ||
| seed = trie.root | ||
| } | ||
| done() | ||
| const genRoot = () => { | ||
| if (i % ERA_SIZE === 0) { | ||
| seed = trie.root | ||
| } | ||
| }, | ||
| cb, | ||
| ) | ||
| } | ||
|
|
||
| if (SYMMETRIC) { | ||
| await trie.put(seed, seed) | ||
| genRoot() | ||
| } else { | ||
| const val = keccak256(seed) | ||
| await trie.put(seed, val) | ||
| genRoot() | ||
| } | ||
|
|
||
| i++ | ||
| } | ||
| } | ||
|
|
||
| const go = async () => { | ||
| const testName = `benchmarks/random.ts | rounds: ${ROUNDS}, ERA_SIZE: ${ERA_SIZE}, ${ | ||
| SYMMETRIC ? 'sys' : 'rand' | ||
| }` | ||
| console.time(testName) | ||
| await run() | ||
| console.timeEnd(testName) | ||
| } | ||
|
|
||
| go() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested both manually locally, updated benchmark suites at least run through. This seems to need more work to be usable - the checkpointing benchmark file e.g. is not taking the samples into account at all e.g., think due to a bug with a reused/side-used
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah thanks for pointing out, I will give it a closer look. |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did an overall
READMEcheck, everything covered, examples look good as well.