-
Notifications
You must be signed in to change notification settings - Fork 0
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 #4 from truck-js/docs/benchmark
docs: add benchmark test
- Loading branch information
Showing
4 changed files
with
81 additions
and
1 deletion.
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
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,43 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const Benchmark = require('benchmark'); | ||
|
||
// eslint-disable-next-line import/no-unresolved | ||
const Stack = require('../lib/index').default; | ||
|
||
const suite = new Benchmark.Suite(); | ||
|
||
const testLength = process.argv[2] || 1000000; | ||
const stack = new Stack(testLength); | ||
const array = new Array(testLength); | ||
|
||
for (let length = 0; length < testLength; length += 1) { | ||
stack.push(length); | ||
array.push(length); | ||
} | ||
|
||
process.stdout.write(`\nRunning benchmark with ${testLength} items:\n\n`); | ||
|
||
suite | ||
.add('Array#pop() ', () => { | ||
const a = array.pop(); | ||
const b = array.pop(); | ||
const c = array.pop(); | ||
array.push(a); | ||
array.push(b); | ||
array.push(c); | ||
}) | ||
.add('Stack#pop() ', () => { | ||
const a = stack.pop(); | ||
const b = stack.pop(); | ||
const c = stack.pop(); | ||
stack.push(a); | ||
stack.push(b); | ||
stack.push(c); | ||
}) | ||
.on('cycle', (event) => { | ||
process.stdout.write(`${String(event.target)}\n`); | ||
}) | ||
.on('complete', function complete() { | ||
process.stdout.write(`Fastest is ${this.filter('fastest').map('name')}\n`); | ||
}) | ||
.run({ async: true }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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