# HG changeset patch # User Oleksandr Gavenko # Date 1410022274 -10800 # Node ID f1dd66c68f4e42673db0b51f8676c7f4ca043b82 # Parent 732aef931a9e3a98f1a19f518631a9f103bbeaec Performance testing toolkit. diff -r 732aef931a9e -r f1dd66c68f4e perf.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/perf.js Sat Sep 06 19:51:14 2014 +0300 @@ -0,0 +1,19 @@ +"use strict"; + +//////////////////////////////////////////////////////////////// +// Performance testing toolkit. +//////////////////////////////////////////////////////////////// + + +/* Invoce 'fn' function 'n' times with 'this' set to 'ctx'. + * Use 'ctx' to initialise test and to pass state between calls. */ +function perf(msg, fn, n, ctx) { + if (typeof n !== "number" || n < 1) + n = 1; + var tsFrom = new Date().getTime(); + for (i = 0; i < n; i++) + fn.call(ctx); + var tsTo = new Date().getTime(); + console.log(msg + ": %f ms, %d u/s", tsTo-tsFrom, i/(tsTo - tsFrom)*1000); +} +