Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. <?php
  2.  
  3. set_time_limit(120000000);
  4.  
  5. $username = 'root';
  6. $password = '';
  7. $dsn = 'mysql:host=127.0.0.1;port=3306;dbname=test';
  8.  
  9. $config = array(
  10.     'queries'   => 1000000000,
  11.  
  12.     'insert'    => true,
  13.     'select'    => true,
  14.  
  15.     'pdo_query'     => true,
  16.     'pdo_prepared'      => true,
  17.     'mysql_'        => true,
  18.     'mysqli'        => true,
  19. );
  20.  
  21.  
  22.  
  23.  
  24. $starttime = microtime(true);
  25.  
  26. if ($config['insert'] && $config['pdo_query'])
  27. {
  28.     $db = new PDO($dsn, $username, $password);
  29.  
  30.     for ($i = 0; $i < $config['queries']; $i++)
  31.     {
  32.         $db->query('INSERT INTO test (wooot) VALUE (' . microtime(true) . ')');
  33.     }
  34.  
  35.     unset($db);
  36.     $end['pdo_query']['insert'] = microtime(true) - $starttime;
  37. }
  38.  
  39. $starttime = microtime(true);
  40.  
  41. if ($config['select'] && $config['pdo_query'])
  42. {
  43.     $db = new PDO($dsn, $username, $password);
  44.  
  45.     $statement = $db->query('SELECT * FROM test WHERE id < ' . time() . ' LIMIT 0, ' . $config['queries']);
  46.  
  47.     while ($result = $statement->fetchObject())
  48.     {
  49.         $var = $result->id;
  50.         $var = $result->wooot;
  51.     }
  52.  
  53.     unset($db, $statement);
  54.     $end['pdo_query']['select'] = microtime(true) - $starttime;
  55. }
  56.  
  57. $starttime = microtime(true);
  58.  
  59. if ($config['insert'] && $config['pdo_prepared'])
  60. {
  61.     $db = new PDO($dsn, $username, $password);
  62.     $statement = $db->prepare('INSERT INTO test (wooot) VALUE (?)');
  63.  
  64.     for ($i = 0; $i < $config['queries']; $i++)
  65.     {
  66.         $statement->execute(array(microtime(true)));
  67.     }
  68.  
  69.     unset($db, $statement);
  70.     $end['pdo_prepared']['insert'] = microtime(true) - $starttime;
  71. }
  72.  
  73. $starttime = microtime(true);
  74.  
  75. if ($config['select'] && $config['pdo_prepared'])
  76. {
  77.     $db = new PDO($dsn, $username, $password);
  78.     $statement = $db->prepare('SELECT * FROM test WHERE id < ? LIMIT 0, ' . $config['queries']);
  79.  
  80.     $statement->execute(array(time()));
  81.  
  82.     while ($result = $statement->fetchObject())
  83.     {
  84.         $var = $result->id;
  85.         $var = $result->wooot;
  86.     }
  87.  
  88.     unset($db, $statement);
  89.     $end['pdo_prepared']['select'] = microtime(true) - $starttime;
  90. }
  91.  
  92. $starttime = microtime(true);
  93.  
  94. if ($config['insert'] && $config['mysql_'])
  95. {
  96.     $con = mysql_connect("localhost", $username, $password);
  97.     mysql_select_db("test", $con);
  98.  
  99.     for ($i = 0; $i < $config['queries']; $i++)
  100.     {
  101.         mysql_query("INSERT INTO test (wooot) VALUES (" . microtime(true) . ")");
  102.     }
  103.  
  104.     mysql_close($con);
  105.     $end['mysql_']['insert'] = microtime(true) - $starttime;
  106. }
  107.  
  108. $starttime = microtime(true);
  109.  
  110. if ($config['select'] && $config['mysql_'])
  111. {
  112.     $con = mysql_connect("localhost", $username, $password);
  113.     mysql_select_db("test", $con);
  114.  
  115.     $result = mysql_query('SELECT * FROM test WHERE id < ' . time() . ' LIMIT 0, ' . $config['queries']);
  116.  
  117.     while($row = mysql_fetch_array($result))
  118.     {
  119.         $var = $row['id'];
  120.         $var = $row['wooot'];
  121.     }
  122.  
  123.     mysql_close($con);
  124.     $end['mysql_']['select'] = microtime(true) - $starttime;
  125. }
  126.  
  127. $starttime = microtime(true);
  128.  
  129. if ($config['insert'] && $config['mysqli'])
  130. {
  131.     $mysqli = new mysqli('localhost', $username, $password, 'test');
  132.  
  133.     for ($i = 0; $i < $config['queries']; $i++)
  134.     {
  135.         $mysqli->query("INSERT INTO test (wooot) VALUES (" . microtime(true) . ")");
  136.     }
  137.  
  138.     $mysqli->close();
  139.     $end['mysqli']['insert'] = microtime(true) - $starttime;
  140. }
  141.  
  142. $starttime = microtime(true);
  143.  
  144. if ($config['select'] && $config['mysqli'])
  145. {
  146.     $mysqli = new mysqli('localhost', $username, $password, 'test');
  147.  
  148.     $result = $mysqli->query("SELECT * FROM test WHERE id < " . time() . ' LIMIT 0, ' . $config['queries']);
  149.     while ($row = $result->fetch_object())
  150.     {
  151.         $var = $row->id;
  152.         $var = $row->wooot;
  153.     }
  154.  
  155.     $mysqli->close();
  156.     $end['mysqli']['select'] = microtime(true) - $starttime;
  157. }
  158.  
  159. echo '<pre>All times include creating and destroying the connection.' . PHP_EOL;
  160. print_r($end);
  161.  
  162. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement