Guest User

Untitled

a guest
Aug 30th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. <?php
  2. /*
  3.  *
  4.  *
  5.  *  Bazadanych
  6.  *  tabela: _comments
  7.  *  Pola:
  8.  *  id, id_post
  9.  *  
  10.  * id - id kolejnego komentarza
  11.  * id_post - id postu, którego dotyczy
  12.  * w funkcji rand brałem wartości od 0-15 (15 postów)
  13.  */
  14.  
  15. // TESTING CODE!
  16.  
  17.  
  18. $start = microtime(1);
  19. $user = "p2";
  20. $pass = "p2";
  21. $base = "p2";
  22. mysql_connect('localhost', $user, $pass);
  23. @mysql_select_db($base) or mysql_error();
  24. $repeat = 3000;
  25.  
  26. // TEST1 MY_SQL COUNT
  27. $start = microtime(1);
  28. for ($a=0; $a<$repeat; $a++)
  29. {
  30.     for($i=0;$i<=15;$i++)
  31.     {
  32.     // CODE HERE!
  33.  
  34.     $sql = "SELECT COUNT(`post_id`) AS `id_count` FROM _comments WHERE `post_id` =".$i."";
  35.     $result = mysql_query( $sql );
  36.     $_count     = mysql_result($result,0,"id_count");
  37.  
  38.     // Dla porównania wyników
  39.     if ($a == $repeat-1)
  40.     echo "Dla: ".$i." = ".$_count."<br \>";
  41.    
  42.  
  43.     }
  44. }
  45. $koniec = microtime(1);
  46. $dane = 'Skrypt wykonal sie w : '.($koniec-$start).'<br/><br/>';
  47. echo $dane;
  48.  
  49. // TEST2 PIEKARZ SKRYPT =/
  50. $start = microtime(1);
  51. for ($a=0; $a<$repeat; $a++)
  52. {
  53.     $sql = "SELECT * FROM `_comments`";
  54.     $result = mysql_query( $sql );
  55.  
  56.     $tab[] = 0;
  57.     for ($i=0; $i<503; $i++)
  58.     {
  59.         $tab[$i] = 0;
  60.     }
  61.     for ($i=0; $i<503; $i++)
  62.     {
  63.         $c = mysql_result($result,$i,"post_id");
  64.         $tab[$c]++;
  65.     }
  66.     if ($a == $repeat-1)
  67.     {
  68.         for ($i=0; $i<=15; $i++)
  69.         {
  70.             echo "Dla: ".$i." = ".$tab[$i]."<br \>";
  71.         }
  72.     }
  73. }
  74.  
  75. $koniec = microtime(1);
  76. $dane = 'Skrypt wykonal sie w : '.($koniec-$start).'<br/><br/>';
  77. echo $dane;
  78.  
  79.  
  80. // KONIEC
  81.  
  82. mysql_close();
  83.  
  84. ?>
Add Comment
Please, Sign In to add comment