Quote:
Originally Posted by 12171217
Is it faster to use the modulus operator to check if it's even or odd? That's what I've always done.
|
PHP Code:
function onCreated() {
for (temp.i = 0; temp.i < 5; temp.i++) {
temp.init = timevar2;
testEven();
temp.sum += timevar2 - temp.init;
}
echo(temp.sum / 5);
}
function testEven() {
for (temp.i = 0; temp.i < 200000; temp.i++) {
isEven(temp.i);
}
}
function isEven(x) {
return int(x / 2) == (x / 2);
}
function isEvenMod(x) {
return (x % 2) == 0;
}
isEvenMod Averaged: 0.281881904
isEven Averaged: 0.300032424
Using modulus is slightly faster (0.01~ seconds in most cases) but I wouldn't consider it something that would become a bottleneck, well in GS2 anyway.