diff --git a/tests/Doctrine/Performance/EntityManagerFactory.php b/tests/Doctrine/Performance/EntityManagerFactory.php index fab5eba767..d759506e46 100644 --- a/tests/Doctrine/Performance/EntityManagerFactory.php +++ b/tests/Doctrine/Performance/EntityManagerFactory.php @@ -2,6 +2,10 @@ namespace Doctrine\Performance; +use Doctrine\Common\EventManager; +use Doctrine\DBAL\Cache\ArrayStatement; +use Doctrine\DBAL\Cache\QueryCacheProfile; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\PDOSqlite\Driver; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; @@ -20,7 +24,7 @@ public static function getEntityManager(array $schemaClassNames) : EntityManager $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ realpath(__DIR__ . '/Models/Cache'), - realpath(__DIR__ . '/Models/GeoNames') + realpath(__DIR__ . '/Models/GeoNames'), ], true)); $entityManager = EntityManager::create( @@ -36,4 +40,29 @@ public static function getEntityManager(array $schemaClassNames) : EntityManager return $entityManager; } + + public static function makeEntityManagerWithNoResultsConnection() : EntityManagerInterface + { + $config = new Configuration(); + + $config->setProxyDir(__DIR__ . '/../Tests/Proxies'); + $config->setProxyNamespace('Doctrine\Tests\Proxies'); + $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([ + realpath(__DIR__ . '/Models/Cache'), + realpath(__DIR__ . '/Models/Generic'), + realpath(__DIR__ . '/Models/GeoNames'), + ], true)); + + // A connection that doesn't really do anything + $connection = new class ([], new Driver(), null, new EventManager()) extends Connection + { + public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) + { + return new ArrayStatement([]); + } + }; + + return EntityManager::create($connection, $config); + } } diff --git a/tests/Doctrine/Performance/Query/QueryBoundParameterProcessingBench.php b/tests/Doctrine/Performance/Query/QueryBoundParameterProcessingBench.php new file mode 100644 index 0000000000..04e17167a0 --- /dev/null +++ b/tests/Doctrine/Performance/Query/QueryBoundParameterProcessingBench.php @@ -0,0 +1,79 @@ +parsedQueryWithInferredParameterType = $entityManager->createQuery($dql); + $this->parsedQueryWithDeclaredParameterType = $entityManager->createQuery($dql); + + foreach (range(1, 10) as $index) { + $this->parsedQueryWithInferredParameterType->setParameter('parameter' . $index, new DateTime()); + $this->parsedQueryWithDeclaredParameterType->setParameter('parameter' . $index, new DateTime(), DateTimeType::DATETIME); + } + + // Force parsing upfront - we don't benchmark that bit in this scenario + $this->parsedQueryWithInferredParameterType->getSQL(); + $this->parsedQueryWithDeclaredParameterType->getSQL(); + } + + public function benchExecuteParsedQueryWithInferredParameterType() : void + { + $this->parsedQueryWithInferredParameterType->execute(); + } + + public function benchExecuteParsedQueryWithDeclaredParameterType() : void + { + $this->parsedQueryWithDeclaredParameterType->execute(); + } +} +