0.1.2 • Published 10 years ago

functime v0.1.2

Weekly downloads
1
License
-
Repository
github
Last release
10 years ago

funcTime

funcTime is a debug utility that wraps around a method and utilizes console.time/End() in order to provide a more sophisticated timing functionality.

npm install functime

Quick Examples

####Internal flow (wrapping the callback from within the caller):

function doStuffWithFiles(['file1','file2','file3'], callback){
    callback = callback.time("FilesProcess");

    // Do some async operations..

    // Callback will be called normally.
    callback(err, result);
}

// Console shows:
// → [INFO] console - FilesProcess: 330ms (avg: 295ms across 6 calls)
// Also: callback.$execTime is 330.

####External flow (wrapping from outside, when calling):

var pkg = require('somePackage');
// Assume pkg has a function 'func' that gets a callback:

function callback(){...}

pkg.func(callback.time("Timing package.func"));
//OR Annonymously:

pkg.func(function(){
    //...
}.time("Timing package.func"));

Documentation

Methods

Wrapped function methods

Times and logs time passed until execution of callback. Keeps stats across calls as well.

Arguments

  • label - (optional) The label to print when reporting time. If not provided, function name will be used.
  • callback - A callback to report to log when called.

Example

function getAppIDs(cb) {
    // Callback is called normally:
    cb = cb.time("getApps execution measure");

    sqlGet("SELECT `app_id` FROM `apps` ", function (err, rows) {
        if (err) {
            cb(err);
            return;
        }
        var result = [];
        rows.forEach(function(row){
          result.push(row.app_id);
        });
        // Callback is called normally:
        cb(null, result);
    });
}

// Console will show:
// → [INFO] console - getApps execution measure: 330ms (avg: 295ms across 6 calls)
// Also: callback.$execTime is now 330.

Returns last call logged time.

Example

function do(){}
do = do.time("Do!");
do();

console.log("Method do() took: %sms", do.$execTime())
// → "Method do() took: 550ms"

Returns average logged time.

Example

function do(){}
do = do.time("Do!");
do();

console.log("Method do() took %sms on average", do.$execTimeAvg())
// → "Method do() took: 550ms on average"

Returns maximal logged time.

Example

function do(){}
do = do.time("Do!");
do();

console.log("Method do() took: %sms on it's longest run.", do.$execTimeMin())
// → "Method do() took: 2345ms on it's longest run."

Returns minimal logged time.

Example

function do(){}
do = do.time("Do!");
do();

console.log("Method do() took: %sms on it's shortest run.", do.$execTimeMin())
// → "Method do() took: 2ms on it's shortest run."

Returns amount of times function was called (amount of executions).

Example

function do(){}
do = do.time("Do!");
do();

console.log("Method do() called %s times", do.$execCount())
// → "Method do() called 5 times"

Coming Up (TDL)

  1. Config object:
    • silent: (false)
    • logLevel: (debug) warn-trace
    • rounding: (2) errParam:0
    • Completely turn off
  2. Support for annonymous functions
  3. Add flush method & label clear.
  4. Full report printing.
  5. Parallel calls support.
0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago