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

56 lines
1.4 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"})
* @AfterMethods({ "dropTable", "disconnect"})
*/
2017-08-23 01:15:33 +02:00
class PDOInsertBench 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();
}
/**
* Each iteration inserts 1000 rows into the table.
* Note that, every insertion calls prepare, bindParam and execute APIs.
*/
2017-08-23 01:15:33 +02:00
public function benchInsertWithPrepare()
{
for ( $i=0; $i<PDOSqlsrvUtil::$loopsPerCRUDIter; $i++)
{
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 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 );
}
}