perf.js
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sun, 19 Oct 2014 01:04:19 +0300
changeset 154 c6d9b84d9391
parent 92 1959a0505639
permissions -rw-r--r--
Fix: return wrong status on move operation (that move not possible up).

"use strict";

////////////////////////////////////////////////////////////////
/** @fileOverview 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 (var 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);
}