vanil-stopwatch-js

1.0.1 • Public • Published

vanil-stopwatch-js v1.0.1

"vanil-stopwatch-js" is a simple (Similar to dotnet's) stopwatch library for monitoring performance. Both node.js and browser compatible.

You can get the latest release from the official npmjs.com feed or from the github releases page.

Build Status

Getting Started

Importing the module

Node.js:

// Import the module.
var Stopwatch = require('vanil-stopwatch-js');

Browser:

<!-- Import the script file (Prefer the minimized version of the module) -->
<script src="vanil-stopwatch.min.js"></script>

Initialization and starting the measurement

Option 1:

// Import the module.
var Stopwatch = require('vanil-stopwatch-js');
 
// Initialize an instance.
var sw = new Stopwatch();
 
// Start the measurement.
sw.start();

Option 2:

// Import the module.
var Stopwatch = require('vanil-stopwatch-js');
 
// Initialize an instance and start it immediately.
var sw = new Stopwatch(true);

Getting the elapsed time

// Import the module.
var Stopwatch = require('vanil-stopwatch-js');
 
// Initialize an instance and start it immediately.
var sw = new Stopwatch(true);
 
// Do an async process.
setTimeout(function(){
    // Stop the current measurement
    sw.stop();
 
    // Printout the elapsed time in milliseconds.
    console.log(sw.elapsedMilliseconds)
 
    // Printout the elapsed time in seconds.
    console.log(sw.elapsedTime.seconds)
 
    // Printout the elapsed time in minutes.
    console.log(sw.elapsedTime.minutes)
 
    // Printout the elapsed time in hours.
    console.log(sw.elapsedTime.hours)
}, 200)

Splitting the measurement

You can split the measurement to laps while it runs.

// Import the module.
var Stopwatch = require('vanil-stopwatch-js');
 
// Initialize an instance and start it immediately.
var sw = new Stopwatch(true);
 
// Do two different process sequentially.
 
// Process #1
setTimeout(function(){
 
    // Split the measurement.
    sw.split('Process #1 done.');
 
    // Process #2
    setTimeout(function(){
 
        // Split the measurement.
        sw.split('Process #2 done.')
 
        // Stop the measurement.
        sw.stop();
 
        // Printout the measurement in milliseconds.
        console.log(sw.elapsedMilliseconds)
 
        // Printout the splitted measurement.
        console.log(sw.laps);
 
    }, 200)
}, 200)

Versioning

Used SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT Licece - see the LICENSE.md file for details.

NOTICE: This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Package Sidebar

Install

npm i vanil-stopwatch-js

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

25.6 kB

Total Files

10

Last publish

Collaborators

  • denizkanmaz