Is there a cost to comments

Benchmark created by T.J. Crowder on


Description

See if there's any measurable cost to comments.

Setup

var result;

Test runner

Ready to run.

Testing in
TestOps/sec
With comments
result = (function() {
    /* Total starts at 1 */
    /* Counter starts at 1,000 */
    var total = 1,
        counter = 500;

    /* Loop through doing
       some work */
    while (--counter) {
        /* Add the length of the string to the total */
        total += String(total).length;
        /* Completely gratuitous comment */
    }

    // All done
    return total;
})();
if (result !== 1580) throw "Error in test";
ready
No comments
result = (function() {
    var total = 1,
        counter = 500;

    while (--counter) {
        total += String(total).length;
    }

    return total;
})();
if (result !== 1580) throw "Error in test";
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.