Socket
Book a DemoInstallSign in
Socket

fprofile

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fprofile

Function profiler.

0.1.3
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

fprofile

A simple function profiler.

The tool hooks to functions (standalone or class methods) and evaluates their execution time and if verbose mode is toggled, also prints their return type and value.

Install

$ npm install fprofile

Usage

var profile = require('fprofile');

/**
 * Adds profiling hooks to object's function(s)
 * @param {Object/Function} object or function
 * @param {Number} threshold, profiler will ignore execution times (in ms) below this value
 * @param {Boolean} verbose mode
 **/
profile(object, threshold, verbose)

Example

Look, test.js contains a few examples:

var profile = require('./main.js');

function factorial(n) {
  return n > 1 ? n * factorial(n - 1) : n;
}

var timedFunction = profile(factorial);
timedFunction(5);
timedFunction(10);
timedFunction(100);

var testObject = {
  factorial: factorial,
  obj: function() {
    return { hello: 'world' };
  }
};

profile(testObject, 0, true);
testObject.factorial(5);
testObject.obj();

profile(console);
console.log('hello');
console.log('world');

Running the code above outputs:

$ node test.js
factorial(5): 0.133ms
factorial(10): 0.02ms
factorial(100): 0.232ms
Object.factorial(5)
  @time 0.194ms
  @type number
  @return 120
Object.obj()
  @time 0.21ms
  @type object
  @return {"hello":"world"}
hello
Console.log("hello"): 0.375ms
world
Console.log("world"): 0.0329ms

Contribute if you want.

Keywords

profiling

FAQs

Package last updated on 18 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.