[ create a new paste ] login | about

Link: http://codepad.org/9zRB740o    [ raw code | output | fork ]

PHP, pasted on Jun 14:
<?php

  $iterations = 100000;

  // ============================

  $i = $rand = $start = $randTime = 0;

  $start = microtime(TRUE);
  while ($i++ < $iterations) {
    $rand = rand();
  }
  $randTime = microtime(TRUE) - $start;

  // ============================

  $i = $rand = $start = $randTimeRange = 0;

  $start = microtime(TRUE);
  while (++$i < $iterations) {
    $rand = rand(0, 100000);
  }
  $randTimeRange = microtime(TRUE) - $start;

  // ============================

  $i = $rand = $start = $mtRandTime = 0;

  $start = microtime(TRUE);
  while ($i++ < $iterations) {
    $rand = mt_rand();
  }
  $mtRandTime = microtime(TRUE) - $start;

  // ============================

  $i = $rand = $start = $mtRandTimeRange = 0;

  $start = microtime(TRUE);
  while (++$i < $iterations) {
    $rand = mt_rand(0, 100000);
  }
  $mtRandTimeRange = microtime(TRUE) - $start;

  // ============================

  echo "
         Iterations: $iterations

             rand(): $randTime
    rand(0, 100000): $randTimeRange

          mt_rand(): $mtRandTime
 mt_rand(0, 100000): $mtRandTimeRange
";


Output:
1
2
3
4
5
6
7
8

         Iterations: 100000

             rand(): 0.092461109161377
    rand(0, 100000): 0.11145687103271

          mt_rand(): 0.030323028564453
 mt_rand(0, 100000): 0.10984301567078


Create a new paste based on this one


Comments: