Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saintedlama/parkbench
Benchmark like a pro
https://github.com/saintedlama/parkbench
Last synced: 16 days ago
JSON representation
Benchmark like a pro
- Host: GitHub
- URL: https://github.com/saintedlama/parkbench
- Owner: saintedlama
- License: isc
- Created: 2016-02-23T15:33:17.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-30T15:05:01.000Z (12 months ago)
- Last Synced: 2024-10-06T06:59:03.669Z (about 1 month ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 48
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# parkbench
![Logo](https://cdn.rawgit.com/saintedlama/parkbench/master/assets/logo.svg)Simplified benchmarks module built on top of benchmark.js (https://benchmarkjs.com/)
## Installation
> npm i parkbench --save
## Usage
parkbench exposes a simplified benchmark interface to benchmark.js
**benchmark.js**
```js
var suite = new Benchmark.Suite;// add tests
suite.add('RegExp#test', function() {
/o/.test('Hello World!');
})
.add('String#indexOf', function() {
'Hello World!'.indexOf('o') > -1;
})
.add('String#match', function() {
!!'Hello World!'.match(/o/);
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ 'async': false });
```**parkbench**
```js
var f = parkbench()
.add('RegExp#test', function() {
/o/.test('Hello World!');
})
.add('String#indexOf', function() {
'Hello World!'.indexOf('o') > -1;
})
.add('String#match', function() {
!!'Hello World!'.match(/o/);
})
.run({ 'async': false });
```### Simplified Async
Benchmarking async functionality in benchmark.js can get a bit weird
**benchmark.js**
```js
var bench = new Benchmark('async', {
defer: true,
fn: function(deferred) {
fs.readFile(__filename, { encoding: 'utf-8'}, function(err) {
deferred.resolve();
});
}
})
.run();
```**parkbench**
With parkbench you can pass a function with a single callback argument. Done!
```js
parkbench('async')
.add('RegExp#test', function(next) {
fs.readFile(__filename, { encoding: 'utf-8'}, next);
})
.run(done);
```## API
**parkbench([name], [options])**
Creates a new parkbench benchmark suite**suite.add([name], functionOrObject)**
Add a benchmark to the benchmark suite**suite.run([options], [callback])**
Run the benchmark suite and print result to console.log