Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hipstersmoothie/perf-table
Compare the performance of functions.
https://github.com/hipstersmoothie/perf-table
Last synced: about 1 month ago
JSON representation
Compare the performance of functions.
- Host: GitHub
- URL: https://github.com/hipstersmoothie/perf-table
- Owner: hipstersmoothie
- License: mit
- Created: 2018-09-30T08:49:35.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-27T06:16:23.000Z (about 6 years ago)
- Last Synced: 2024-09-08T14:12:39.887Z (2 months ago)
- Language: TypeScript
- Size: 145 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
{
perf-table
Compare the performance of functions.
result *= result + item;
});
}// Table is a promise that resolve when done printing/writing the table.
// Resolves with formatted table
const data = await table([
['for', forLoop],
['for of', forOf],
['while', whileLoop],
['forEach', forEach]
]);
```OUTPUT:
```sh
╔═════════╤════════════╤══════════════════════════╤═════════════╗
║ NAME │ OPS/SEC │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE ║
╟─────────┼────────────┼──────────────────────────┼─────────────╢
║ for │ 11,251,638 │ ± 0.71% │ 186 ║
╟─────────┼────────────┼──────────────────────────┼─────────────╢
║ while │ 10,804,607 │ ± 1.75% │ 185 ║
╟─────────┼────────────┼──────────────────────────┼─────────────╢
║ for of │ 7,223,835 │ ± 1.17% │ 167 ║
╟─────────┼────────────┼──────────────────────────┼─────────────╢
║ forEach │ 4,146,640 │ ± 1.72% │ 183 ║
╚═════════╧════════════╧══════════════════════════╧═════════════╝
```### Providing Tuples with other configuration
If you want to configure the table further you will have to put the array demonstrated above in the `compare` key of your options.
```js
table({
compare: [
['for', forLoop],
['for of', forOf],
['while', whileLoop],
['forEach', forEach]
],
...
});
```### Benchmark Options
`perf-table` is on top of [benchmark.js](https://benchmarkjs.com) and you can configure the each comparison run with [benchmark.js options](https://benchmarkjs.com/docs#options).
```js
table({
compare: [ ... ],
options: {
minSamples: 500
}
});
```### Output Modes
`perf-table` comes with a few output modes pre configured.
- cli (default) - output a table formatted for the CLI
- md - output a markdown table
- html - output a html table
- csv - output the table data in csv```js
table({
compare: [ ... ],
renderer: 'html'
})
```### Custom Renderer
If you want to control how the table renders, pass a function to `renderer` and this will be used to render the perf table data.
```js
const renderCSV: IRenderFunction = data =>
data.reduce((text, line) => text + `\n${line.join(',')}`, '');table({
compare: [ ... ],
renderer: renderCSV
})
```### Writing to a file
By default `perf-table` just prints the table to the console. If you provide a file path in the `file` option the table output will be written to that path.
```js
table({
compare: [ ... ],
file: 'test.txt'
})
```### Force Logging
When the `file` option is provided the table will not be logged to the console. To override this behavior also pass `log: true`.
```js
table({
compare: [ ... ],
file: 'test.txt',
log: true
})
```### BundlePhobia Stats
You can display [bundlePhobia](https://bundlephobia.com/) column with your perf table to really compare yourself against the competition.
```js
table({
compare: [ ... ],
bundle: true
})
```#### Link
To add a link the to [bundlePhobia](https://bundlephobia.com/) output set `bundle` to `'link'`.
```js
table({
compare: [ ... ],
bundle: 'link'
})
```