Advertisement
Guest User

Untitled

a guest
Apr 29th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3.  
  4. define('LOOP_TIMES', 100000);
  5.  
  6. echo timeit(function($i){
  7.     $filename = __DIR__."/demo{$i}.txt";
  8.     return is_readable($filename)? file_get_contents($filename):false;
  9. }),"\n";
  10.  
  11.  
  12.  
  13. function timeit($func, $times=LOOP_TIMES){
  14.     $_start = microtime(1);
  15.     for($i=0; $i<$times; $i++){
  16.         $func($i);
  17.     }
  18.     return microtime(1) - $_start;
  19. }
  20.  
  21.  
  22. echo timeit(function($i){
  23.     $filename = __DIR__."/demo{$i}.txt";
  24.     return file_get_contents($filename);
  25. }),"\n";
  26.  
  27.  
  28.  
  29. for($i=0; $i<LOOP_TIMES*10; $i++){
  30.     $_key = 'test_'.($i<<1);
  31.     $GLOBALS[$_key] = $i;
  32. }
  33.  
  34.  
  35. echo timeit(function($i){
  36.     $key = 'test_'.$i;
  37.     return isset($GLOBALS[$key])? $GLOBALS[$key]: false;
  38. },LOOP_TIMES*20),"\n";
  39.  
  40.  
  41. echo timeit(function($i){
  42.     $key = 'test_'.$i;
  43.     return $GLOBALS[$key];
  44. },LOOP_TIMES*20),"\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement