count-1 or --count?

JavaScript performance comparison

Test case created

Preparation code

<div id="timespan">5</div>

Preparation code output

5

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
--count
var timetainer = document.getElementById("timespan");
var count= timetainer.innerHTML;
var counter=setInterval(timer, 1000);

function timer() { count= --count;
    if(count < 0) { clearInterval(counter); timespired(); return; }
    timetainer.innerHTML = count
}

function timespired() { console.log("Espired") };
pending…
count-1
var timetainer = document.getElementById("timespan");
var count= timetainer.innerHTML;
var counter=setInterval(timer, 1000);

function timer() { count= count-1;
    if(count < 0) { clearInterval(counter); timespired(); return; }
    timetainer.innerHTML = count
}

function timespired() { console.log("Espired") };
pending…

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

Compare results of other browsers

0 comments

Add a comment