title: What's slowing for loops/assignment vs. C?
body: <p>I have a collection of PHP scripts that are extremely CPU intensive, juggling millions of calculations across hundreds of simultaneous users.</p>
  
  <p>I'm trying to find a way to speed up the internals of PHP variable assignment, and looping sequences vs C.</p>
  
  <p>Although PHP is obviously loosely typed, is there any way/extension to specifically assign type (assign, <em>not</em> cast, which seems even more expensive) in a C-style fashion?</p>
  
  <p>Here's what I mean.</p>
  
  <p>This is some dummy code in C:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  unsigned long add=0;
  
  for(unsigned long x=0;x&lt;100000000;x++) {
      add = x*59328409238;
  }
  printf("x is %ld\n",add);
  </code></pre>
  
  <p>}</p>
  
  <p>Pretty self-explanatory -- it loops 100 million times, multiples each iteration by an arbitrary number of some 59 billion, assigns it to a variable and prints it out.</p>
  
  <p>On my Macbook, compiling it and running it produced:</p>
  
  <pre><code>lees-macbook-pro:Desktop lee$ time ./test2
  x is 5932840864471590762
  
  real    0m0.266s
  user    0m0.253s
  sys  0m0.002s
  </code></pre>
  
  <p>Pretty darn fast!</p>
  
  <p>A similar script in PHP 5.3 CLI...</p>
  
  <pre><code>&lt;?php
  for($i=0;$i&lt;100000000;$i++){
      $a=$i*59328409238;
  }
  echo $a."\n";
  ?&gt;
  </code></pre>
  
  <p>... produced:</p>
  
  <pre><code>lees-macbook-pro:Desktop lee$ time /Applications/XAMPP/xamppfiles/bin/php test3.php
  5.93284086447E+18
  
  real    0m22.837s
  user    0m22.110s
  sys  0m0.078s
  </code></pre>
  
  <p>Over 22 seconds vs 0.2!</p>
  
  <p>I realize PHP is doing a heck of a lot more behind the scenes than this simple C program - but is there any way to make the PHP internals to behave more 'natively' on primitive types and loops?</p>