https://github.com/macrat/asyncmark
A benchmarking library for javascript that supports Promise.
https://github.com/macrat/asyncmark
benchmark-framework benchmarking javascript-library npm-package
Last synced: 4 months ago
JSON representation
A benchmarking library for javascript that supports Promise.
- Host: GitHub
- URL: https://github.com/macrat/asyncmark
- Owner: macrat
- License: mit
- Created: 2018-02-11T03:38:45.000Z (about 8 years ago)
- Default Branch: dev
- Last Pushed: 2023-01-07T02:19:16.000Z (about 3 years ago)
- Last Synced: 2025-07-04T01:08:17.161Z (7 months ago)
- Topics: benchmark-framework, benchmarking, javascript-library, npm-package
- Language: TypeScript
- Homepage: https://macrat.github.io/AsyncMark/
- Size: 4.33 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
AsyncMark
=========
A benchmarking library for javascript that supports Promise.
[](https://nodei.co/npm/asyncmark/)
[](https://github.com/macrat/AsyncMark/actions?query=workflow%3Atest)
[](https://codeclimate.com/github/macrat/AsyncMark/test_coverage)
[](https://codeclimate.com/github/macrat/AsyncMark/maintainability)
[](https://david-dm.org/macrat/asyncmark)
[](https://david-dm.org/macrat/asyncmark?type=dev)
[](https://david-dm.org/macrat/asyncmark?type=optional)
[](https://github.com/macrat/AsyncMark/blob/master/LICENSE)
[](https://macrat.github.io/AsyncMark/)
You can [try benchmark on the web](https://macrat.github.io/AsyncMark/on-web/).
## be simple
``` javascript
import { Benchmark } from 'asyncmark';
new Benchmark(function() {
return new Promise((resolve, reject) => {
setTimeout(resolve, 100);
});
}).run().catch(console.error);
```
## be customizable
``` javascript
import { Suite } from 'asyncmark';
const suite = new Suite({
name: 'ways to find a character',
beforeEach() {
this.text = 'hello world';
},
parallel: true,
});
suite.add(function() {
/o/.test(this.text);
});
suite.add({
name: 'String#indexOf',
before() {
console.log('starting String#indexOf...');
},
fun() {
this.text.indexOf('o') > -1;
},
});
suite.add(new Benchmark({
name: 'String#match',
fun() {
Boolean(this.text.match(/o/));
},
after(result) {
console.log('String#match is done! ' + result);
},
}));
suite.run()
.then(results => {
let min = results[0];
results.forEach(x => {
if (min.average > x.average) {
min = x;
}
});
console.log(min.name + ' is best way!');
})
.catch(err => console.error(err));
```
## with unit test
``` javascript
import { Benchmark } from 'asyncmark';
describe('benchmark test', function() {
it('foobar', async function() {
const result = await new Benchmark(function() {
# do_something
}).run();
result.assert("<100ms"); # expect faster than 100ms.
});
});
```
## installation
### Node.js
``` shell
$ npm install asyncmark
```
#### ES6
``` javascript
import { Benchmark, Suite } from 'asyncmark';
```
#### CommonJS
``` javascript
const AsyncMark = require('asyncmark');
const Benchmark = AsyncMark.Benchmark;
const Suite = AsyncMark.Suite;
```
### Browser
``` html
const Benchmark = AsyncMark.Benchmark;
const Suite = AsyncMark.Suite;
```