Neatly Positioned Magazines

    mstime

    0.6.9 • Public • Published

    mstime

    NPM version Build Status Coverage Status NPM

    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 (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

    Demo Screenshot

    Install

    $ npm install --save mstime
    

    Usage

    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

    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:

    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

    License

    MIT © Duc Nguyen

    Install

    npm i mstime

    DownloadsWeekly Downloads

    4,880

    Version

    0.6.9

    License

    MIT

    Unpacked Size

    51.1 kB

    Total Files

    21

    Last publish

    Collaborators

    • ngduc