JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<span>Conditional: </span><span id="conditional"></span>
</div>
<div>
<span>Modulo: </span><span id="modulo"></span>
</div>
JavaScript
var iterations = 10000000,
threshold = 100;
function getTime() {
var date = new Date();
return date.getTime();
}
function conditionalTest() {
var element = document.getElementById('conditional'),
x = 0,
time = getTime();
for (var i = 0; i < iterations; i++) {
x++;
if (x == threshold) {
x = 0;
}
}
time = (getTime() - time);
element.innerText = time + ' ' + x;
}
function moduloTest() {
var element = document.getElementById('modulo'),
x = 0,
time = getTime();
for (var i = 0; i < iterations; i++) {
x = (x + 1) % threshold;
}
time = (getTime() - time);
element.innerText = time + ' ' + x;
}
conditionalTest();
moduloTest();