multiply by 2

From: Date: Mon, 20 May 2002 04:03:00 +0000
Subject: multiply by 2
Groups: php.general 
Request: Send a blank email to php-general+get-98413@lists.php.net to get a copy of this message
I was doing some timing of a function on the weekend and in one of the loops, I had to multiply a variable by 2 - easy enough - $i*2 but then I remembered that in C, it's quicker to do a left shift - so $i<<1 but this actually took longer to execute in php than the $i*2 - can anyone confirm my test? I iterated ~28,000 times. Each time, there was 2 places where I was doing the left shift. The time (including all the other stuff I was doing in the function) for $i*2 was ~12secs, and $i<<1 was ~19secs. I am running PHP4.0.6 (download cgi version from php.net) on a win98 system (500MHz Celeron if that changes anything)

« previous php.general (#98413) next »