php-sqlsrv/test/Performance/benchmark/pdo_sqlsrv/PDOUpdateBench.php

75 lines
1.9 KiB
PHP
Raw Normal View History

2017-05-06 02:32:09 +02:00
<?php
use PDOSqlsrvPerfTest\PDOSqlsrvUtil;
2017-08-23 01:15:33 +02:00
include_once __DIR__ . "/../../lib/CRUDBaseBenchmark.php";
2017-05-06 02:32:09 +02:00
/**
* @BeforeMethods({"connect", "setTableName", "createTable", "generateInsertValues", "insertWithPrepare", "generateUpdateValues", "generateUpdateParams"})
* @AfterMethods({"dropTable", "disconnect"})
*/
2017-08-23 01:15:33 +02:00
class PDOUpdateBench extends CRUDBaseBenchmark
{
2017-05-06 02:32:09 +02:00
private $conn;
private $tableName;
private $insertValues;
private $updateValues;
private $updateParams;
2017-08-23 01:15:33 +02:00
public function setTableName()
{
2017-05-06 02:32:09 +02:00
$this->tableName = "datatypes_".rand();
}
2017-08-23 01:15:33 +02:00
public function connect()
{
2017-05-06 02:32:09 +02:00
$this->conn = PDOSqlsrvUtil::connect();
}
2017-08-23 01:15:33 +02:00
public function createTable()
{
2017-05-06 02:32:09 +02:00
PDOSqlsrvUtil::createCRUDTable( $this->conn, $this->tableName );
}
2017-08-23 01:15:33 +02:00
public function generateInsertValues()
{
2017-05-06 02:32:09 +02:00
$this->insertValues = PDOSqlsrvUtil::generateInsertValues();
}
2017-08-23 01:15:33 +02:00
public function insertWithPrepare()
{
2017-05-06 02:32:09 +02:00
PDOSqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues );
}
2017-08-23 01:15:33 +02:00
public function generateUpdateValues()
{
2017-05-06 02:32:09 +02:00
$this->updateValues = PDOSqlsrvUtil::generateUpdateValues();
}
2017-08-23 01:15:33 +02:00
public function generateUpdateParams()
{
2017-05-06 02:32:09 +02:00
$this->updateParams = PDOSqlsrvUtil::generateUpdateParams();
}
/**
* Each iteration inserts a row into the table, updateWithPrepare() updates that row 1000 times.
* Note that, every update calls prepare, bindParam and execute APIs.
*/
2017-08-23 01:15:33 +02:00
public function benchUpdateWithPrepare()
{
for( $i=0; $i<PDOSqlsrvUtil::$loopsPerCRUDIter; $i++ )
{
2017-08-25 02:05:34 +02:00
PDOSqlsrvUtil::updateWithPrepare( $this->conn, $this->tableName, $this->updateValues, $this->updateParams );
2017-05-06 02:32:09 +02:00
}
}
2017-08-23 01:15:33 +02:00
public function dropTable()
{
2017-05-06 02:32:09 +02:00
PDOSqlsrvUtil::dropTable( $this->conn, $this->tableName );
}
2017-08-23 01:15:33 +02:00
public function disconnect()
{
2017-05-06 02:32:09 +02:00
PDOSqlsrvUtil::disconnect( $this->conn );
}
}