Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- *
- *
- * Bazadanych
- * tabela: _comments
- * Pola:
- * id, id_post
- *
- * id - id kolejnego komentarza
- * id_post - id postu, którego dotyczy
- * w funkcji rand brałem wartości od 0-15 (15 postów)
- */
- // TESTING CODE!
- $start = microtime(1);
- $user = "p2";
- $pass = "p2";
- $base = "p2";
- mysql_connect('localhost', $user, $pass);
- @mysql_select_db($base) or mysql_error();
- $repeat = 3000;
- // TEST1 MY_SQL COUNT
- $start = microtime(1);
- for ($a=0; $a<$repeat; $a++)
- {
- for($i=0;$i<=15;$i++) // zliczamy dla każdego z 15 postów
- {
- // CODE HERE!
- $sql = "SELECT COUNT(`post_id`) AS `id_count` FROM _comments WHERE `post_id` =".$i."";
- $result = mysql_query( $sql );
- $_count = mysql_result($result,0,"id_count");
- // Dla porównania wyników
- if ($a == $repeat-1) // OSTATNI OBIEG WYSWIETLAMY DANE
- echo "Dla: ".$i." = ".$_count."<br \>";
- }
- }
- $koniec = microtime(1);
- $dane = 'Skrypt wykonal sie w : '.($koniec-$start).'<br/><br/>';
- echo $dane;
- // TEST2 PIEKARZ SKRYPT =/
- $start = microtime(1);
- for ($a=0; $a<$repeat; $a++)
- {
- $sql = "SELECT * FROM `_comments`"; // zasysamy wszystkie
- $result = mysql_query( $sql ); // ^ ^ ^ ^ ^ ^ ^ ^ ^
- $num = mysql_numrows($result); // ile mamy wierszy
- $tab[] = 0;
- for ($i=0; $i<$num; $i++) // zerujemy, nie wiem czy w PHP trzeba?
- {
- $tab[$i] = 0;
- }
- for ($i=0; $i<$num; $i++)
- {
- $c = mysql_result($result,$i,"post_id"); // magic
- $tab[$c]++; // magic
- }
- if ($a == $repeat-1) // OSTATNI OBIEG WYSWIETLAMY DANE
- {
- for ($i=0; $i<=15; $i++)
- {
- echo "Dla: ".$i." = ".$tab[$i]."<br \>";
- }
- }
- }
- $koniec = microtime(1);
- $dane = 'Skrypt wykonal sie w : '.($koniec-$start).'<br/><br/>';
- echo $dane;
- // KONIEC
- mysql_close();
- ?>
Add Comment
Please, Sign In to add comment