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.2 to 0.0.3

13

lib/benchit.js

@@ -6,13 +6,16 @@ // Generated by CoffeeScript 1.4.0

one = function(codeBlock, callback) {
var done, eventLoop, start;
var done, eventLoop, nanoseconds, seconds, start, _ref;
switch (codeBlock.length) {
case 0:
start = Date.now();
start = process.hrtime();
codeBlock();
return Date.now() - start;
_ref = process.hrtime(start), seconds = _ref[0], nanoseconds = _ref[1];
return (seconds * 1000) + (nanoseconds / 1000000);
default:
done = false;
eventLoop = function() {
var _ref1;
if (done) {
return typeof callback === "function" ? callback(Date.now() - start) : void 0;
_ref1 = process.hrtime(start), seconds = _ref1[0], nanoseconds = _ref1[1];
return typeof callback === "function" ? callback((seconds * 1000) + (nanoseconds / 1000000)) : void 0;
} else {

@@ -22,3 +25,3 @@ return process.nextTick(eventLoop);

};
start = Date.now();
start = process.hrtime();
codeBlock(function() {

@@ -25,0 +28,0 @@ return done = true;

{
"name": "benchit",
"description": "Really simple benchmarking library",
"description": "Really simple code benchmarking library for nodejs/coffeescript",
"author": "Chris Khoo",
"version": "0.0.2",
"version": "0.0.3",
"main": "lib/benchit.js",

@@ -19,3 +19,10 @@ "licenses": [

"node": ">=0.8.11"
},
"scripts": {
"test": "cake test"
},
"devDependencies": {
"coffee-script": "latest",
"mocha": "latest"
}
}

@@ -0,1 +1,3 @@

[![Build Status](https://travis-ci.org/khoomeister/benchit.png)](https://travis-ci.org/khoomeister/benchit)
Benchit

@@ -42,1 +44,21 @@ =======

```
Improvements to be made
-----------------------
* This is more of an educational activity at the moment. [Benchmark.js](http://benchmarkjs.com/) is definitely the much better alternative to use, especially for testing across browsers.
* However it does suffer a weakness in that if one wanted to test something like sending larger packets across a network or sorting a larger list, there isn't a parameter passed to the function that tells the code to try with a larger "size". This is important since some algorithm running times increase exponentially with larger inputs as opposed to running the same algorithm with the same input multiple times.
* Ideally, what should happen is:
* Run each test case at a starting size.
* Increase the "size" until a certain amount of time has elapsed for any test case (let's say a second). The number of times it ran (i.e. iterations) is tracked, and sets the baseline so that any one test doesn't run too long.
* For each test case, run it for that number of iterations repeatedly until a number of seconds have passed (let's say 5-10 seconds).
* Return the average number of operations per second & standard deviation for each test case.
* However, what is preventing me from implementing this is that I'm still trying to understand what is meant by "statistical significance".
Discussion
----------
* The function compilation feature in benchmark.js aims to make benchmarks more accurate, however as far as I know, the only extra cost in not inlining the test code into the loop is an extra function call, which is a constant time operation (as long as the same number of parameters are used for each call). I'm personally more interested in relative comparisons between code blocks, hence I'm most likely not going to implement this any time soon.
Interesting reads
-----------------
* <http://calendar.perfplanet.com/2010/bulletproof-javascript-benchmarks/>
* <http://monsur.hossa.in/2012/12/11/benchmarkjs.html>

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