Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: mathi
- * Date: 10/10/2018
- * Time: 15:58
- */
- function genererChaineAleatoire($longueur)
- {
- $caracteres = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $longueurMax = strlen($caracteres);
- $chaineAleatoire = '';
- for ($i = 0; $i < $longueur; $i++)
- {
- $chaineAleatoire .= $caracteres[rand(0, $longueurMax - 1)];
- }
- return $chaineAleatoire;
- }
- function dureeEntreDeuxPoints()
- {
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "tp2mysql";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if($conn->connect_error){
- die("Connection echouée : " . $conn->connect_error);
- }
- $config = "SET query_cache_size = 2048M;";
- $conn->query($config);
- $debut = microtime(true);
- $total_rows = 5000;
- for($j = 0; $j < 1000; $j++){
- $query = "INSERT INTO users (type, adresse, nom, supprime, email) VALUES ";
- for($i = 1; $i <= $total_rows; $i++) {
- $query .= "(1,'" . genererChaineAleatoire(5) . "','" . genererChaineAleatoire(5) . "',0,'" . genererChaineAleatoire(5) . "'),";
- }
- $query = substr($query, 0, -1);
- $conn->query($query);
- }
- $fin = microtime(true);
- $conn->close();
- $diff = $fin - $debut;
- return $diff;
- }
- echo 'La durée entre deux points est de ' . dureeEntreDeuxPoints() . 'ms';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement