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

63 lines
1.5 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", "insertWithPrepare"})
* @AfterMethods({ "dropTable", "disconnect"})
*/
2017-08-23 01:15:33 +02:00
class SqlsrvFetchBench 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 = 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();
}
2017-08-23 01:15:33 +02:00
public function insertWithPrepare()
{
2017-05-06 02:32:09 +02:00
SqlsrvUtil::insertWithPrepare( $this->conn, $this->tableName, $this->insertValues );
}
/**
* Each iteration inserts a row into the table, benchFetchWithPrepare() fetches that row 1000 times.
* Note that, every fetch calls prepare, execute and fetch APIs.
*/
2017-08-23 01:15:33 +02:00
public function benchFetchWithPrepare()
{
for( $i=0; $i<SqlsrvUtil::$loopsPerCRUDIter; $i++)
{
2017-05-06 02:32:09 +02:00
SqlsrvUtil::fetchWithPrepare( $this->conn, $this->tableName );
}
}
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 );
}
}