<commit_before><?php
/**
 * Check what is faster MySQL, MySQLi or PDO on simple queries;
 * @file    MysqlVsMysqliVsPdoRead.php
 *
 * PHP version 5.4+
 *
 * @author  <NAME> <alex at itvault dot info>
 * @date    Fri Sep 27 13:06:09 2013
 * @copyright The BSD 3-Clause License
 */

namespace Tests;

use Application\DbConnectException;
use Application\DbQueryException;
use Application\TestApplication;
use mysqli;
use PDO;
use Veles\Tools\CliProgressBar;
use Veles\Tools\Timer;

/**
 * Class MysqlVsMysqliVsPdoRead
 *
 * @author  <NAME> <alex at itvault dot info>
 */
class MysqlVsMysqliVsPdoRead extends TestApplication
{
	protected static $class_dependencies = ['PDO', 'MySQLi'];
	protected static $ext_dependencies = ['pdo_mysql', 'mysqli', 'mysql'];

	protected static $repeats = 1000;

	private static $user = 'root';
	private static $host = 'localhost';
	private static $password = '';
	private static $database = 'php_bench_test';

	final public static function run()
	{
		self::prepareTables();
		$repeats = self::getRepeats();

		$sql = 'SELECT * FROM test';
		$bar = new CliProgressBar($repeats);

		$link = mysql_connect(self::$host, self::$user, self::$password);
		mysql_select_db(self::$database);
		for ($i = 1; $i <= $repeats; ++$i) {
			$result = [];
			Timer::start();
			$res = mysql_query($sql, $link);
			while ($row = mysql_fetch_assoc($res)) $result[] = $row;
			Timer::stop();
			$bar->update($i);
		}

		mysql_free_result($res);
		self::addResult('MySQL', Timer::get());

		$bar = new CliProgressBar($repeats);

		Timer::reset();
		$mysqli = new mysqli(
			self::$host, self::$user, self::$password, self::$database
		);
		for ($i = 1; $i <= $repeats; ++$i) {
			$result = [];
			Timer::start();
			$res = $mysqli->query($sql);
			while ($row = $res->fetch_assoc()) $result[] = $row;
			Timer::stop();
			$bar->update($i);
		}

		$res->free();
		self::addResult('MySQLi', Timer::get());

		$bar = new CliProgressBar($repeats);

		Timer::reset();
		$dsn = 'mysql:dbname=' . self::$database . ';'
			 . 'host=' . self::$host . ';'
			 . 'charset=utf8';<commit_msg>Supress mysql_* function notices. Fixes #6.<commit_after><?php
/**
 * Check what is faster MySQL, MySQLi or PDO on simple queries;
 * @file    MysqlVsMysqliVsPdoRead.php
 *
 * PHP version 5.4+
 *
 * @author  <NAME> <alex at itvault dot info>
 * @date    Fri Sep 27 13:06:09 2013
 * @copyright The BSD 3-Clause License
 */

namespace Tests;

use Application\DbConnectException;
use Application\DbQueryException;
use Application\TestApplication;
use mysqli;
use PDO;
use Veles\Tools\CliProgressBar;
use Veles\Tools\Timer;

/**
 * Class MysqlVsMysqliVsPdoRead
 *
 * @author  <NAME> <alex at itvault dot info>
 */
class MysqlVsMysqliVsPdoRead extends TestApplication
{
	protected static $class_dependencies = ['PDO', 'MySQLi'];
	protected static $ext_dependencies = ['pdo_mysql', 'mysqli', 'mysql'];

	protected static $repeats = 1000;

	private static $user = 'root';
	private static $host = 'localhost';
	private static $password = '';
	private static $database = 'php_bench_test';

	final public static function run()
	{
		self::prepareTables();
		$repeats = self::getRepeats();

		$sql = 'SELECT * FROM test';
		$bar = new CliProgressBar($repeats);

		$link = @mysql_connect(self::$host, self::$user, self::$password);
		@mysql_select_db(self::$database);
		for ($i = 1; $i <= $repeats; ++$i) {
			$result = [];
			Timer::start();
			$res = @mysql_query($sql, $link);
			while ($row = @mysql_fetch_assoc($res)) $result[] = $row;
			Timer::stop();
			$bar->update($i);
		}

		@mysql_free_result($res);
		self::addResult('MySQL', Timer::get());

		$bar = new CliProgressBar($repeats);

		Timer::reset();
		$mysqli = new mysqli(
			self::$host, self::$user, self::$password, self::$database
		);
		for ($i = 1; $i <= $repeats; ++$i) {
			$result = [];
			Timer::start();
			$res = $mysqli->query($sql);
			while ($row = $res->fetch_assoc()) $result[] = $row;
			Timer::stop();
			$bar->update($i);
		}

		$res->free();
		self::addResult('MySQLi', Timer::get());

		$bar = new CliProgressBar($repeats);

		Timer::reset();
		$dsn = 'mysql:dbname=' . self::$database . ';'
			 . 'host=' . self::$host . ';'
			 . 'charset=utf8';
{'fraction_non_alphanumeric': 0.18460441910192446, 'fraction_numerical': 0.010691375623663579, 'mean_word_length': 4.288944723618091, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4489881', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1503, 'n_words': 356}