Comparing version 0.0.23 to 0.0.24
@@ -51,6 +51,21 @@ /** | ||
function dummy( ) { } | ||
var __timerOverhead; | ||
function calibrate( ) { | ||
// timer overhead is ~ 1/100k sec, that throws off some timings | ||
var i, t1, t2; | ||
t1 = fptime(); | ||
for (i=0; i<100; i++) t2 = fptime(); | ||
__timerOverhead = (t2 - t1) / 100; | ||
// the call overhead is 1 part in 50m, we dont try to correct for that | ||
} | ||
function timeit( nloops, f, msg, callback ) { | ||
var __i, __fn = (typeof f === 'function' ? f : Function(f)); | ||
var __t1, __t2; | ||
if (typeof msg === 'function') { callback = msg; msg = undefined; } | ||
if (__timerOverhead === undefined) calibrate(nloops); | ||
if (!callback) { | ||
@@ -60,10 +75,11 @@ // node v0.11.x strongly penalizes parsing the function in the timed loop; v0.10 did not | ||
__fn(); | ||
__fn(); | ||
var __t1 = fptime(); | ||
__t1 = fptime(); | ||
for (__i=0; __i<nloops; ++__i) { | ||
__fn(); | ||
} | ||
var __t2 = fptime(); | ||
__t2 = fptime(); | ||
var __duration = (__t2 - __t1); | ||
var __duration = (__t2 - __t1 - __timerOverhead); | ||
reportit(f, nloops, __duration, msg ? msg : "AR:"); | ||
@@ -81,3 +97,3 @@ } | ||
__t2 = fptime(); | ||
var __duration = (__t2 - __t1); | ||
var __duration = (__t2 - __t1 - __timerOverhead); | ||
reportit(f, nloops, __duration, msg ? msg : "AR:"); | ||
@@ -87,3 +103,3 @@ } | ||
__fn(function() { | ||
if (__depth++ > 40) { __depth = 0; setImmediate(__launchNext); } | ||
if (__depth++ > 400) { __depth = 0; setImmediate(__launchNext); } | ||
else __launchNext(); | ||
@@ -90,0 +106,0 @@ }); |
{ | ||
"name": "arlib", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"description": "Andras' Utility Functions", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -102,3 +102,4 @@ # arlib | ||
If function is a string it will be eval-d. The function under test is run | ||
once to compile it (and not include the cost of compilation in the timings), | ||
twice to compile it (and not include the cost of compilation in the timings) | ||
and prime the node optimizer, | ||
then count times back-to-back for the benchmark. | ||
@@ -105,0 +106,0 @@ |
59065
31
1324
151