-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reapply ray pow improvements (#82)
* Revert "revert: revert changes to pow (#81)" This reverts commit 095a878. * fix: corretly pass date
- Loading branch information
Showing
10 changed files
with
286 additions
and
22 deletions.
There are no files selected for viewing
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,7 @@ | ||
# Getting started | ||
|
||
This is a micro benchmark suite we use to test if optimizations are paying off. | ||
To not burden normal users with installing unnecessary deps we don't include them automatically. | ||
If you want to run the benchmark install `benchmark` manually. `npm i -g benchmark` | ||
|
||
Single micro-benchmarks can be executed by running `node ./benchmarks/<benchmarkName>` |
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,59 @@ | ||
const { | ||
rayPow, | ||
binomialApproximatedRayPow, | ||
valueToZDBigNumber, | ||
RAY, | ||
SECONDS_PER_YEAR, | ||
} = require('../dist'); | ||
const Benchmark = require('benchmark'); | ||
|
||
Benchmark.options.minSamples = 200; | ||
const PRECISION = 2; | ||
const results = []; | ||
const suite = new Benchmark.Suite(); | ||
|
||
const timeDelta = valueToZDBigNumber(60 * 60 * 24); | ||
const rayPowIn = valueToZDBigNumber('323788616402133497883602337') | ||
.dividedBy(SECONDS_PER_YEAR) | ||
.plus(RAY); | ||
const binomialApproximatedRayPowIn = valueToZDBigNumber( | ||
'323788616402133497883602337' | ||
).dividedBy(SECONDS_PER_YEAR); | ||
|
||
suite | ||
// add tests | ||
.add('rayPow', () => { | ||
rayPow(rayPowIn, timeDelta); | ||
}) | ||
.add('binomialApproximatedRayPow', () => { | ||
binomialApproximatedRayPow(binomialApproximatedRayPowIn, timeDelta); | ||
}) | ||
|
||
// add listeners | ||
.on('cycle', event => | ||
results.push({ | ||
name: event.target.name, | ||
hz: event.target.hz, | ||
'margin of error': `±${Number(event.target.stats.rme).toFixed(2)}%`, | ||
'runs sampled': event.target.stats.sample.length, | ||
}) | ||
) | ||
.on('complete', function() { | ||
const lowestHz = results.slice().sort((a, b) => a.hz - b.hz)[0].hz; | ||
|
||
console.table( | ||
results | ||
.sort((a, b) => b.hz - a.hz) | ||
.map(result => ({ | ||
...result, | ||
hz: Math.round(result.hz).toLocaleString(), | ||
numTimesFaster: | ||
Math.round((10 ** PRECISION * result.hz) / lowestHz) / | ||
10 ** PRECISION, | ||
})) | ||
.reduce((acc, { name, ...cur }) => ({ ...acc, [name]: cur }), {}) | ||
); | ||
console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
}) | ||
|
||
.run({ async: false }); |
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
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
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.