Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yashladha/node-microbenchmark

Micro benchmarking library for Node.JS 🚀
https://github.com/yashladha/node-microbenchmark

benchmarking microbenchmark node

Last synced: 3 months ago
JSON representation

Micro benchmarking library for Node.JS 🚀

Awesome Lists containing this project

README

        

## node-microbenchmark

[![npm version](https://badge.fury.io/js/node-microbenchmark.svg)](https://badge.fury.io/js/node-microbenchmark)

A micro benchmarking library inspired from [google-benchmark](https://github.com/google/benchmark)

Features available:
* Benchmarking synchronous functions
* Benchmarking of asynchronous functions
* Support for Promises
* High precision benchmark (upto nanoseconds precision)

### Benchmarking of synchronous functions
```javascript
const { benchmark, show } = require('node-microbenchmark');

const slowFn = () => {
for (var i = 0; i < 1e4; ++i);
}

const fastFn = () => {}

benchmark(slowFn);
benchmark(fastFn);

show();
```

### Benchmarking of asynchronous functions
```javascript
const benchmark = require('../index');

const slowTimer = () => new Promise(res => setTimeout(res, 200));
const fastTimer = () => new Promise(res => setTimeout(res, 50));

const fn = async () => {
await benchmark.benchmarkPromise(slowTimer);
await benchmark.benchmarkPromise(fastTimer);
benchmark.show();
};

fn();
```

![node-microbenchmark](https://raw.githubusercontent.com/yashladha/node-microbenchmark/master/images/node-microbenchmark.png)

## Future enhancements

* Benchmark async code like promises.

## Author

* [yashLadha](https://github.com/yashLadha)