# mstime

> a lightweight module (2KB gzip) to measure & visualize code performance in millisecond (ms), run on Node & browser. No dependencies!

Latest version **0.6.9** (published 2019-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install mstime
pnpm add mstime
yarn add mstime
bun add mstime
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.9 |
| Published | 2019-06-06 |
| First published | 2017-10-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=4.0.0 |
| Dependencies | 0 |
| Unpacked size | 49.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Duc Nguyen |
| Maintainers | ngduc |
| Keywords | measure, time, performance, optimize |

## Links

- npm: https://www.npmjs.com/package/mstime
- Repository: https://github.com/ngduc/mstime
- Issues: https://github.com/ngduc/mstime/issues
- npm.io page: https://npm.io/package/mstime

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 0.6.9 (latest) — 2019-06-06
- 0.6.8 — 2019-06-06
- 0.6.4 — 2018-10-22
- 0.6.3 — 2018-10-21
- 0.6.2 — 2018-10-21
- 0.6.1 — 2018-10-05
- 0.6.0 — 2018-10-05
- 0.5.0 — 2018-10-04
- 0.4.2 — 2018-10-04
- 0.4.0 — 2018-10-04
- 0.3.4 — 2018-10-04
- 0.3.3 — 2018-10-04
- 0.3.2 — 2018-10-04
- 0.3.0 — 2018-10-04
- 0.1.5 — 2017-10-19
- … 9 more at https://npm.io/package/mstime/versions

## README

# mstime

[![NPM version](https://img.shields.io/npm/v/mstime.svg?style=flat-square)](https://npmjs.org/package/mstime)
[![Build Status](https://img.shields.io/travis/ngduc/mstime/master.svg?style=flat-square)](https://travis-ci.org/ngduc/mstime) [![Coverage Status](https://img.shields.io/codecov/c/github/ngduc/mstime/master.svg?style=flat-square)](https://codecov.io/gh/ngduc/mstime/branch/master)
[![NPM](https://img.shields.io/npm/dt/mstime.svg?style=flat-square)](https://www.npmjs.com/package/mstime)

a lightweight module (2KB gzip) to measure & visualize code performance in millisecond (ms), run on Node & browser. No dependencies!

_mstime_ uses [performance.now Web API](https://developers.google.com/web/updates/2012/08/When-milliseconds-are-not-enough-performance-now) (high resolution timer) to measure the difference between start & end points.

_mstime_ has an easy **Plugin System** which lets you write simple (yet powerful) plugins to process/visualize data in different ways.

## Example / Demo

* Example in Node: https://runkit.com/ngduc/mstime
* Example in Browser: https://rawgit.com/ngduc/mstime/master/docs/demo/index.html
* Example in Codesandbox: https://codesandbox.io/s/jlnp3owm2y

[![Demo Screenshot](/docs/screenshot-01.png)](https://rawgit.com/ngduc/mstime/master/docs/demo/index.html)

## Install

    $ npm install --save mstime

## Usage

```js
import mstime from "mstime";

mstime.start("codeblock1");
processData(); // your function
const result = mstime.end("codeblock1");
```

`result` is a JSON object: (all values are in milliseconds)

```
{
  entries: [
    { start: 41991120.53, end: 41991133.04, diff: 12.50 }
  ]
  last: 12.50,
  sum: 12.50,
  avg: 12.50
}
```

Available builds (dist): CommonJS, ES, UMD.

## Config

```js
mstime.config({
  decimalDigits: 4, // default: 2
  consoleTime: true // use console.time & console.timeEnd, default: false
});
```

## Plugins

Plugins offer more useful abilities on the captured data.

A plugin is just a function that processes data and returns this structure:

```js
const pluginExample = ({ config }) => ({
  name: "msplugin-example",
  run: (allData, timerData) => {
    const output = "do something useful here with allData & timerData...";
    return {
      // property & value can be anything
    };
  }
});
```

`run` function will get called on `mstime.end` and its result will be put in "timerData.plugins"

### List of Plugins:
```
- msplugin-use-local-storage   use localStorage to store timer data. 
- msplugin-trim-mean           calculate for trimmed mean.
- msplugin-chartist            plot data using Chartist.

- msplugin-find-outliers       (In Progress: find outliers)
- msplugin-post-to-api         (In Progress: post timer data to API)
- msplugin-save-to-db          (In Progress: save timer data to DB)
- (create your plugin & add it here...)
```

## Documentation

- [Change Log](/CHANGELOG.md)

## License

MIT © [Duc Nguyen](https://github.com/ngduc)

---
_Source: https://npm.io/package/mstime · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
