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

66 lines
1.6 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"})
* @AfterMethods({ "dropTable","disconnect"})
*/
2017-08-23 01:15:33 +02:00
class PDODeleteBench extends CRUDBaseBenchmark
{
2017-05-06 02:32:09 +02:00
private $conn;
private $tableName;
private $insertValues;
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()
{
for( $i=0; $i<PDOSqlsrvUtil::$loopsPerCRUDIter; $i++ )
{
2017-05-06 02:32:09 +02:00
PDOSqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues );
}
}
/**
* Each iteration inserts 1000 rows into the table, benchDelete deletes top row from the table 1000 times.
* Note that, every delete calls prepare and execute APIs.
*/
2017-08-23 01:15:33 +02:00
public function benchDelete()
{
for( $i=0; $i<PDOSqlsrvUtil::$loopsPerCRUDIter; $i++ )
{
2017-05-06 02:32:09 +02:00
PDOSqlsrvUtil::deleteWithPrepare( $this->conn, $this->tableName );
}
}
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 );
}
}