Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: mathi
  5. * Date: 10/10/2018
  6. * Time: 15:58
  7. */
  8.  
  9.  
  10. function genererChaineAleatoire($longueur)
  11. {
  12. $caracteres = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  13. $longueurMax = strlen($caracteres);
  14. $chaineAleatoire = '';
  15. for ($i = 0; $i < $longueur; $i++)
  16. {
  17. $chaineAleatoire .= $caracteres[rand(0, $longueurMax - 1)];
  18. }
  19. return $chaineAleatoire;
  20. }
  21.  
  22. function dureeEntreDeuxPoints()
  23. {
  24.  
  25. $servername = "localhost";
  26. $username = "root";
  27. $password = "";
  28. $dbname = "tp2mysql";
  29.  
  30. $conn = new mysqli($servername, $username, $password, $dbname);
  31. if($conn->connect_error){
  32. die("Connection echouée : " . $conn->connect_error);
  33. }
  34.  
  35. $config = "SET query_cache_size = 2048M;";
  36. $conn->query($config);
  37.  
  38. $debut = microtime(true);
  39.  
  40.  
  41. $total_rows = 5000;
  42.  
  43. for($j = 0; $j < 1000; $j++){
  44. $query = "INSERT INTO users (type, adresse, nom, supprime, email) VALUES ";
  45.  
  46. for($i = 1; $i <= $total_rows; $i++) {
  47. $query .= "(1,'" . genererChaineAleatoire(5) . "','" . genererChaineAleatoire(5) . "',0,'" . genererChaineAleatoire(5) . "'),";
  48.  
  49. }
  50. $query = substr($query, 0, -1);
  51. $conn->query($query);
  52. }
  53.  
  54.  
  55. $fin = microtime(true);
  56. $conn->close();
  57.  
  58. $diff = $fin - $debut;
  59. return $diff;
  60. }
  61. echo 'La durée entre deux points est de ' . dureeEntreDeuxPoints() . 'ms';
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement