Thread: Prelude
View Single Post
  #7  
Old 12-18-2010, 07:34 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by 12171217 View Post
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.0temp.5temp.i++) {
    
temp.init timevar2;
    
testEven();
    
temp.sum += timevar2 temp.init;
  }
  echo(
temp.sum 5);
}

function 
testEven() {
  for (
temp.0temp.200000temp.i++) {
    
isEven(temp.i);
  }
}

function 
isEven(x) {
  return 
int(2) == (2);
}

function 
isEvenMod(x) {
  return (
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.
__________________
Quote:

Last edited by fowlplay4; 12-18-2010 at 08:18 PM..
Reply With Quote