Advertisement
Guest User

File functions profiling

a guest
Nov 12th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2.  
  3. function test_with_file_exists_no_file() {
  4.     $fileName = uniqid('');
  5.     if (file_exists($fileName)) {
  6.         require_once($fileName);
  7.     }
  8. }
  9.  
  10.  
  11. function test_with_file_exists_with_file($fileName) {
  12.     if (file_exists($fileName)) {
  13.         require_once($fileName);
  14.     }
  15. }
  16.  
  17. function test_without_file_exists_no_file() {
  18.     $fileName = uniqid('');
  19.     @include_once($fileName);
  20. }
  21.  
  22.  
  23. function test_without_file_exists_with_file($fileName) {
  24.     @include_once($fileName);
  25. }
  26.  
  27. function run_test_with_file() {
  28.     for ($i = 0; $i < 10000; $i++) {
  29.         $fileName = uniqid('test_');
  30.         touch($fileName);
  31.         test_with_file_exists_with_file($fileName);
  32.         unlink($fileName);
  33.     }
  34.  
  35.     for ($i = 0; $i < 10000; $i++) {
  36.         $fileName = uniqid('test_');
  37.         touch($fileName);
  38.         test_without_file_exists_with_file($fileName);
  39.         unlink($fileName);
  40.     }
  41. }
  42.  
  43. run_test_with_file();
  44. for ($i = 0; $i < 10000; $i++) {
  45.     test_without_file_exists_no_file();
  46.     test_with_file_exists_no_file();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement