simple-timer

A simple timer/stopwatch implementation.

simple-timer

A simple timer/stopwatch implementation.

Specify any number of timers to be managed simultaneously, referenced by any name you give them. In the following example one timer, named "my timer", is used.

// Load dependencies. 
var simple_timer = require('simple-timer')
var http = require('http')
 
// Start timer. 
simple_timer.start('my timer')
var url = 'http://example.com'
http.get(url, function(res) {
    // Stop timer. 
    simple_timer.stop('my timer')
    console.log('HTTP request to %s took %s milliseconds.', url, simple_timer.get('my timer').delta)
})

This should produce output like the following.

> node example.js
HTTP request to http://example.com took 125 milliseconds.

Passing true as the second parameter to the start and stop methods gives verbose output.

// Load dependencies. 
var simple_timer = require('simple-timer')
var http = require('http')
 
// Start timer. 
simple_timer.start('my timer', true)
http.get('http://example.com', function(res) {
    // Stop timer. 
    simple_timer.stop('my timer', true)
})

The example above produces output like the following.

> node example.js
[TIMER] start - my timer
[TIMER] stop  - my timer
[TIMER] delta - my timer: 119 (0.119 seconds)

Simple.

This repository is made available to the public as open source software under the MIT License.