Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

benchit

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

benchit - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

78

lib/benchit.js
// Generated by CoffeeScript 1.4.0
(function() {
var benchit;
var many, one;
benchit = function(name, codeBlock, elapsedBlock) {
var afterBlock, done, eventLoop, setDone, start;
if (elapsedBlock == null) {
elapsedBlock = function(name, elapsed) {
return console.log("" + name + " elapsed: " + elapsed + "ms");
};
}
one = function(codeBlock, callback) {
var done, eventLoop, start;
switch (codeBlock.length) {

@@ -16,14 +11,8 @@ case 0:

codeBlock();
return elapsedBlock(name, Date.now() - start);
return Date.now() - start;
default:
done = false;
afterBlock = null;
setDone = function(after) {
done = true;
return afterBlock = after;
};
eventLoop = function() {
if (done) {
elapsedBlock(name, Date.now() - start);
return typeof afterBlock === "function" ? afterBlock() : void 0;
return typeof callback === "function" ? callback(Date.now() - start) : void 0;
} else {

@@ -34,3 +23,5 @@ return process.nextTick(eventLoop);

start = Date.now();
codeBlock(setDone);
codeBlock(function() {
return done = true;
});
return eventLoop();

@@ -40,4 +31,55 @@ }

module.exports = benchit;
many = function(codeBlocks, elapsedBlock) {
var finalize, name, nameList, recurse, setup, teardown;
if (elapsedBlock == null) {
elapsedBlock = function(name, elapsed) {
return console.log("" + name + " elapsed: " + elapsed + "ms");
};
}
nameList = (function() {
var _results;
_results = [];
for (name in codeBlocks) {
if (name !== 'setup' && name !== 'teardown' && name !== 'finalize') {
_results.push(name);
}
}
return _results;
})();
setup = codeBlocks.setup;
teardown = codeBlocks.teardown;
finalize = codeBlocks.finalize;
recurse = function(name) {
var codeBlock;
if (!(name != null)) {
return typeof finalize === "function" ? finalize() : void 0;
}
if (typeof setup === "function") {
setup();
}
codeBlock = codeBlocks[name];
switch (codeBlock.length) {
case 0:
elapsedBlock(name, one(codeBlock));
if (typeof teardown === "function") {
teardown();
}
return recurse(nameList.shift());
default:
return one(codeBlock, function(elapsed) {
elapsedBlock(name, elapsed);
if (typeof teardown === "function") {
teardown();
}
return recurse(nameList.shift());
});
}
};
return recurse(nameList.shift());
};
exports.one = one;
exports.many = many;
}).call(this);
{
"name": "benchit",
"description": "Really simple benchmarking tool",
"description": "Really simple benchmarking library",
"author": "Chris Khoo",
"version": "0.0.1",
"version": "0.0.2",
"main": "lib/benchit.js",

@@ -7,0 +7,0 @@ "licenses": [

Benchit
=======
This is a really simple benchmarking function used to return the running time of code blocks. It supports asynchronous and synchronous code.
This is a really simple benchmarking library thats return the running time of code. It supports asynchronous and synchronous code.
Usage
-----
### Synchronous code block
```coffeescript
benchit.one ->
...
# (will return elapsed time in milliseconds)
```
### Asynchronous code block
```coffeescript
benchit.one (done) ->
...
done() # call when finished
, (elapsed) ->
console.log elapsed
```
### Multiple code blocks
```coffeescript
benchit.many
synchronousCode: ->
...
asynchronousCode: (done) ->
...
done() # call when finished
, (name, elapsed) -> console.log "#{name} elapsed: #{elapsed}ms"
###
Output:
synchronousCode elapsed: 100ms
asynchronousCode elapsed: 200ms
(note: 2nd parameter is optional)
###
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc