Unverified Commit 715b5898 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3923 from morozov/remove-performance-tests

Removed performance tests
parents 9dcb41e4 cb81e400
......@@ -44,11 +44,7 @@
<testsuites>
<testsuite name="Doctrine DBAL Test Suite">
<directory>./tests/Doctrine/Tests/DBAL</directory>
<exclude>./tests/Doctrine/Tests/DBAL/Performance</exclude>
</testsuite>
<testsuite name="Doctrine DBAL Performance Test Suite">
<directory>./tests/Doctrine/Tests/DBAL/Performance</directory>
<directory>tests/Doctrine/Tests/DBAL</directory>
</testsuite>
</testsuites>
......@@ -57,14 +53,4 @@
<directory suffix=".php">lib/Doctrine</directory>
</whitelist>
</filter>
<listeners>
<listener class="Doctrine\Tests\DbalPerformanceTestListener"/>
</listeners>
<groups>
<exclude>
<group>performance</group>
</exclude>
</groups>
</phpunit>
<?php
namespace Doctrine\Tests\DBAL\Performance;
use DateTime;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalPerformanceTestCase;
/**
* @group performance
*/
class TypeConversionPerformanceTest extends DbalPerformanceTestCase
{
/**
* @throws DBALException
*
* @dataProvider itemCountProvider
*/
public function testDateTimeTypeConversionPerformance(int $count) : void
{
$value = new DateTime();
$type = Type::getType('datetime');
$platform = $this->connection->getDatabasePlatform();
$this->startTiming();
for ($i = 0; $i < $count; $i++) {
$type->convertToDatabaseValue($value, $platform);
}
$this->stopTiming();
}
/**
* @return mixed[][]
*/
public static function itemCountProvider() : iterable
{
return [
'100 items' => [100],
'1000 items' => [1000],
'10000 items' => [10000],
'100000 items' => [100000],
];
}
}
<?php
namespace Doctrine\Tests;
use function microtime;
/**
* Base class for all DBAL performance tests.
*
* Tests implemented in this class must call startTiming at the beginning
* and stopTiming at the end of all tests. Tests that do not start or stop
* timing will fail.
*/
abstract class DbalPerformanceTestCase extends DbalFunctionalTestCase
{
/**
* time the test started
*
* @var float
*/
private $startTime;
/**
* elapsed run time of the last test
*
* @var float
*/
private $runTime;
/**
* {@inheritdoc}
*/
protected function assertPostConditions() : void
{
// If a perf test doesn't start or stop, it fails.
self::assertNotNull($this->startTime, 'Test timing was started');
self::assertNotNull($this->runTime, 'Test timing was stopped');
}
/**
* begin timing
*/
protected function startTiming() : void
{
$this->startTime = microtime(true);
}
/**
* end timing
*/
protected function stopTiming() : void
{
$this->runTime = microtime(true) - $this->startTime;
}
/**
* @return float elapsed test execution time
*/
public function getTime() : float
{
return $this->runTime;
}
}
<?php
namespace Doctrine\Tests;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use function get_class;
use function printf;
use function str_replace;
/**
* Listener for collecting and reporting results of performance tests
*/
class DbalPerformanceTestListener implements TestListener
{
use TestListenerDefaultImplementation;
/** @var string[][] */
private $timings = [];
/**
* {@inheritdoc}
*/
public function endTest(Test $test, float $time) : void
{
// This listener only applies to performance tests.
if (! ($test instanceof DbalPerformanceTestCase)) {
return;
}
// we identify perf tests by class, method, and dataset
$class = str_replace('\\Doctrine\\Tests\\DBAL\\Performance\\', '', get_class($test));
if (! isset($this->timings[$class])) {
$this->timings[$class] = [];
}
// Store timing data for each test in the order they were run.
$this->timings[$class][$test->getName(true)] = $test->getTime();
}
/**
* Report performance test timings.
*
* Note: __destruct is used here because PHPUnit doesn't have a
* 'All tests over' hook.
*/
public function __destruct()
{
if (empty($this->timings)) {
return;
}
// Report timings.
print "\nPerformance test results:\n\n";
foreach ($this->timings as $class => $tests) {
printf("%s:\n", $class);
foreach ($tests as $test => $time) {
printf("\t%s: %.3f seconds\n", $test, $time);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment