Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(120000000);
- $username = 'root';
- $password = '';
- $dsn = 'mysql:host=127.0.0.1;port=3306;dbname=test';
- $config = array(
- 'queries' => 1000000000,
- 'insert' => true,
- 'select' => true,
- 'pdo_query' => true,
- 'pdo_prepared' => true,
- 'mysql_' => true,
- 'mysqli' => true,
- );
- $starttime = microtime(true);
- if ($config['insert'] && $config['pdo_query'])
- {
- $db = new PDO($dsn, $username, $password);
- for ($i = 0; $i < $config['queries']; $i++)
- {
- $db->query('INSERT INTO test (wooot) VALUE (' . microtime(true) . ')');
- }
- unset($db);
- $end['pdo_query']['insert'] = microtime(true) - $starttime;
- }
- $starttime = microtime(true);
- if ($config['select'] && $config['pdo_query'])
- {
- $db = new PDO($dsn, $username, $password);
- $statement = $db->query('SELECT * FROM test WHERE id < ' . time() . ' LIMIT 0, ' . $config['queries']);
- while ($result = $statement->fetchObject())
- {
- $var = $result->id;
- $var = $result->wooot;
- }
- unset($db, $statement);
- $end['pdo_query']['select'] = microtime(true) - $starttime;
- }
- $starttime = microtime(true);
- if ($config['insert'] && $config['pdo_prepared'])
- {
- $db = new PDO($dsn, $username, $password);
- $statement = $db->prepare('INSERT INTO test (wooot) VALUE (?)');
- for ($i = 0; $i < $config['queries']; $i++)
- {
- $statement->execute(array(microtime(true)));
- }
- unset($db, $statement);
- $end['pdo_prepared']['insert'] = microtime(true) - $starttime;
- }
- $starttime = microtime(true);
- if ($config['select'] && $config['pdo_prepared'])
- {
- $db = new PDO($dsn, $username, $password);
- $statement = $db->prepare('SELECT * FROM test WHERE id < ? LIMIT 0, ' . $config['queries']);
- $statement->execute(array(time()));
- while ($result = $statement->fetchObject())
- {
- $var = $result->id;
- $var = $result->wooot;
- }
- unset($db, $statement);
- $end['pdo_prepared']['select'] = microtime(true) - $starttime;
- }
- $starttime = microtime(true);
- if ($config['insert'] && $config['mysql_'])
- {
- $con = mysql_connect("localhost", $username, $password);
- mysql_select_db("test", $con);
- for ($i = 0; $i < $config['queries']; $i++)
- {
- mysql_query("INSERT INTO test (wooot) VALUES (" . microtime(true) . ")");
- }
- mysql_close($con);
- $end['mysql_']['insert'] = microtime(true) - $starttime;
- }
- $starttime = microtime(true);
- if ($config['select'] && $config['mysql_'])
- {
- $con = mysql_connect("localhost", $username, $password);
- mysql_select_db("test", $con);
- $result = mysql_query('SELECT * FROM test WHERE id < ' . time() . ' LIMIT 0, ' . $config['queries']);
- while($row = mysql_fetch_array($result))
- {
- $var = $row['id'];
- $var = $row['wooot'];
- }
- mysql_close($con);
- $end['mysql_']['select'] = microtime(true) - $starttime;
- }
- $starttime = microtime(true);
- if ($config['insert'] && $config['mysqli'])
- {
- $mysqli = new mysqli('localhost', $username, $password, 'test');
- for ($i = 0; $i < $config['queries']; $i++)
- {
- $mysqli->query("INSERT INTO test (wooot) VALUES (" . microtime(true) . ")");
- }
- $mysqli->close();
- $end['mysqli']['insert'] = microtime(true) - $starttime;
- }
- $starttime = microtime(true);
- if ($config['select'] && $config['mysqli'])
- {
- $mysqli = new mysqli('localhost', $username, $password, 'test');
- $result = $mysqli->query("SELECT * FROM test WHERE id < " . time() . ' LIMIT 0, ' . $config['queries']);
- while ($row = $result->fetch_object())
- {
- $var = $row->id;
- $var = $row->wooot;
- }
- $mysqli->close();
- $end['mysqli']['select'] = microtime(true) - $starttime;
- }
- echo '<pre>All times include creating and destroying the connection.' . PHP_EOL;
- print_r($end);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement