コード例 #1
0
ファイル: DbGeneratorTest.php プロジェクト: ahmeti/php-bench
 public function run()
 {
     $this->prepareTables();
     $repeats = $this->getRepeats();
     $sql = 'SELECT txt FROM test';
     $bar = new CliProgressBar($repeats);
     for ($i = 1; $i <= $repeats; ++$i) {
         Timer::start();
         $result = ODb::rows($sql);
         foreach ($result as $value) {
         }
         Timer::stop();
         $bar->update($i);
     }
     $this->addResult('non-generator', Timer::get());
     Timer::reset();
     $bar = new CliProgressBar($repeats);
     // Db class initialization
     $pool = new ConnectionPool();
     $conn = new PdoConnection('master');
     $conn->setDsn("mysql:host=localhost;dbname={$this->database};charset=utf8")->setUserName('root')->setPassword('')->setOptions([PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false]);
     $pool->addConnection($conn, true);
     PdoAdapter::setPool($pool);
     Db::setAdapter(PdoAdapter::instance());
     for ($i = 1; $i <= $repeats; ++$i) {
         Timer::start();
         $result = Db::rows($sql);
         foreach ($result as $value) {
         }
         Timer::stop();
         $bar->update($i);
     }
     $this->addResult('generator', Timer::get());
     $this->cleanup();
 }
コード例 #2
0
ファイル: ConnectionPool.php プロジェクト: ahmeti/php-bench
 /**
  * Add connection to connection pool
  *
  * @param PdoConnection $conn
  * @param bool $default Flag is this connection default or not
  * @return $this
  * @see DbConnection
  */
 public function addConnection(PdoConnection $conn, $default = false)
 {
     $this->pool[$conn->getName()] = $conn;
     if ($default) {
         $this->conn_name = $conn->getName();
     }
     return $this;
 }