This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from ethereumjs/upgradeTestsToTS
Upgrade test suite to TS
- Loading branch information
Showing
36 changed files
with
877 additions
and
785 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as async from 'async' | ||
import * as crypto from 'crypto' | ||
const Trie = require('../dist/index.js').CheckpointTrie | ||
|
||
let iterations = 500 | ||
let samples = 20 | ||
let i = 0 | ||
|
||
function iterTest(numOfIter: number, cb: Function) { | ||
let vals = [] as any | ||
let keys = [] as any | ||
|
||
for (i = 0; i <= numOfIter; i++) { | ||
vals.push(crypto.pseudoRandomBytes(32)) | ||
keys.push(crypto.pseudoRandomBytes(32)) | ||
} | ||
|
||
let hrstart = process.hrtime() | ||
let numOfOps = 0 | ||
let trie = new Trie() | ||
|
||
for (i = 0; i < numOfIter; i++) { | ||
trie.put(vals[i], keys[i], function () { | ||
trie.checkpoint() | ||
trie.get(Buffer.from('test'), function () { | ||
numOfOps++ | ||
if (numOfOps === numOfIter) { | ||
const hrend = process.hrtime(hrstart) | ||
cb(hrend) | ||
} | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
i = 0 | ||
let avg = [0, 0] | ||
|
||
async.whilst( | ||
function () { | ||
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, | ||
) | ||
}, | ||
) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('./checkpointing') | ||
require('./random') |
This file contains 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 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 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
Oops, something went wrong.