php-sqlsrv/test/Performance/benchmark/sqlsrv/SqlsrvInsertBench.php

57 lines
1.3 KiB
PHP
Raw Normal View History

2017-05-06 02:32:09 +02:00
<?php
use SqlsrvPerfTest\SqlsrvUtil;
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 SqlsrvInsertBench 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-06-03 01:46:03 +02:00
2017-08-23 01:15:33 +02:00
public function connect()
{
2017-05-06 02:32:09 +02:00
$this->conn = SqlsrvUtil::connect();
}
2017-08-23 01:15:33 +02:00
public function createTable()
{
2017-05-06 02:32:09 +02:00
SqlsrvUtil::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 = SqlsrvUtil::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<SqlsrvUtil::$loopsPerCRUDIter; $i++ )
{
2017-05-06 02:32:09 +02:00
SqlsrvUtil::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
SqlsrvUtil::dropTable( $this->conn, $this->tableName );
}
2017-08-23 01:15:33 +02:00
public function disconnect()
{
2017-05-06 02:32:09 +02:00
SqlsrvUtil::disconnect( $this->conn );
}
}