if (@(!(include __DIR__ . '/vendor/autoload.php'))) { echo 'Install Lean Mapper using `composer install`'; exit(1); } require_once __DIR__ . '/Model/Mapper.php'; require_once __DIR__ . '/Model/Entity/Employee.php'; require_once __DIR__ . '/Model/Entity/Salary.php'; require_once __DIR__ . '/Model/Entity/Department.php'; require_once __DIR__ . '/Model/Repository/EmployeesRepository.php'; date_default_timezone_set('Europe/Prague'); $limit = 500; $connection = new Connection(array('username' => 'root', 'password' => '', 'database' => 'employees')); $time = -microtime(TRUE); ob_start(); $entityFactory = new DefaultEntityFactory(); $mapper = new Mapper(); $employeesRepository = new EmployeesRepository($connection, $mapper, $entityFactory); foreach ($employeesRepository->findAll($limit) as $employee) { echo "{$employee->firstName} {$employee->lastName} ({$employee->empNo})\n"; echo "Salaries:\n"; foreach ($employee->salaries as $salary) { echo $salary->salary, "\n"; } echo "Departments:\n"; foreach ($employee->departments as $department) { echo $department->deptName, "\n"; } } ob_end_clean(); print_benchmark_result('LeanMapper');
<?php require __DIR__ . '/../print_benchmark_result.php'; require __DIR__ . '/vendor/NotORM/NotORM.php'; require __DIR__ . '/NotORMStructure.php'; date_default_timezone_set('Europe/Prague'); $useCache = TRUE; $limit = 500; $connection = new PDO('mysql:dbname=employees', 'root', ''); $notorm = new NotORM($connection, new NotORMStructure(), $useCache ? new NotORM_Cache_File(__DIR__ . '/temp/notorm') : NULL); $time = -microtime(TRUE); ob_start(); foreach ($notorm->employees()->limit($limit) as $employee) { echo "{$employee['first_name']} {$employee['last_name']} ({$employee['emp_no']})\n"; echo "Salaries:\n"; foreach ($employee->salaries() as $salary) { echo $salary['salary'], "\n"; } echo "Departments:\n"; foreach ($employee->dept_emp() as $relationship) { echo $relationship->departments['dept_name'], "\n"; } } ob_end_clean(); print_benchmark_result('NotOrm');
<?php require __DIR__ . '/../print_benchmark_result.php'; if (@(!(include __DIR__ . '/vendor/autoload.php'))) { echo 'Install Nette using `composer install`'; exit(1); } $useCache = TRUE; date_default_timezone_set('Europe/Prague'); $connection = new Nette\Database\Connection('mysql:dbname=employees', 'root', ''); $cacheStorage = new Nette\Caching\Storages\FileStorage(__DIR__ . '/temp'); $connection->setCacheStorage($useCache ? $cacheStorage : NULL); $connection->setDatabaseReflection(new Nette\Database\Reflection\DiscoveredReflection($useCache ? $cacheStorage : NULL)); $dao = $connection; $time = -microtime(TRUE); ob_start(); foreach ($dao->table('employees')->limit(500) as $employe) { echo "{$employe->first_name} {$employe->last_name} ({$employe->emp_no})\n"; echo "Salaries:\n"; foreach ($employe->related('salaries') as $salary) { echo $salary->salary, "\n"; } echo "Departments:\n"; foreach ($employe->related('dept_emp') as $department) { echo $department->dept->dept_name, "\n"; } } ob_end_clean(); print_benchmark_result('NDB 2.0', 'Nette: ' . Nette\Framework::VERSION);
require_once __DIR__ . '/model/EmployeesMapper.php'; require_once __DIR__ . '/model/EmployeesRepository.php'; require_once __DIR__ . '/model/Salary.php'; require_once __DIR__ . '/model/SalariesMapper.php'; require_once __DIR__ . '/model/SalariesRepository.php'; date_default_timezone_set('Europe/Prague'); $useCache = TRUE; $limit = 500; $cacheStorage = new Nette\Caching\Storages\FileStorage(__DIR__ . '/temp'); $connection = new Nette\Database\Connection('mysql:dbname=employees', 'root', ''); $structure = new Nette\Database\Structure($connection, $useCache ? $cacheStorage : NULL); $conventions = new Nette\Database\Conventions\DiscoveredConventions($structure); $context = new Nette\Database\Context($connection, $structure, $conventions, $useCache ? $cacheStorage : NULL); $time = -microtime(TRUE); ob_start(); $model = new StaticModel(['employees' => new model\EmployeesRepository(new model\EmployeesMapper($context)), 'salarieys' => new model\SalariesRepository(new model\SalariesMapper($context)), 'departments' => new model\DepartmentsRepository(new model\DepartmentsMapper($context))], $cacheStorage); $employees = $model->employees->findOverview($limit); foreach ($employees as $employee) { echo "{$employee->firstName} {$employee->lastName} ({$employee->id})\n"; echo "Salaries:\n"; foreach ($employee->salaries as $salary) { echo "-", $salary->salary, "\n"; } echo "Departments:\n"; foreach ($employee->departments as $department) { echo "-", $department->name, "\n"; } } ob_end_clean(); print_benchmark_result('Nextras\\Orm');
<?php require __DIR__ . '/../print_benchmark_result.php'; if (@(!(include __DIR__ . '/vendor/autoload.php'))) { echo 'Install Nette using `composer install`'; exit(1); } $useCache = TRUE; date_default_timezone_set('Europe/Prague'); $connection = new Nette\Database\Connection('mysql:dbname=employees', 'root', ''); $cacheStorage = new Nette\Caching\Storages\FileStorage(__DIR__ . '/temp'); $dao = new Nette\Database\Context($connection, new Nette\Database\Reflection\DiscoveredReflection($connection, $useCache ? $cacheStorage : NULL), $useCache ? $cacheStorage : NULL); $time = -microtime(TRUE); ob_start(); foreach ($dao->table('employees')->limit(500) as $employe) { echo "{$employe->first_name} {$employe->last_name} ({$employe->emp_no})\n"; echo "Salaries:\n"; foreach ($employe->related('salaries') as $salary) { echo $salary->salary, "\n"; } echo "Departments:\n"; foreach ($employe->related('dept_emp') as $department) { echo $department->dept->dept_name, "\n"; } } ob_end_clean(); print_benchmark_result('NDB 2.2', 'Nette: 2.2.x');
<?php require __DIR__ . '/../print_benchmark_result.php'; if (@(!(include __DIR__ . '/vendor/autoload.php'))) { echo 'Install Nette using `composer install`'; exit(1); } $useCache = TRUE; date_default_timezone_set('Europe/Prague'); $cacheStorage = new Nette\Caching\Storages\FileStorage(__DIR__ . '/temp'); $connection = new Nette\Database\Connection('mysql:dbname=employees', 'root', ''); $structure = new Nette\Database\Structure($connection, $cacheStorage); $conventions = new Nette\Database\Conventions\DiscoveredConventions($structure); $context = new Nette\Database\Context($connection, $structure, $conventions, $useCache ? $cacheStorage : NULL); $time = -microtime(TRUE); ob_start(); foreach ($context->table('employees')->limit(500) as $employe) { echo "{$employe->first_name} {$employe->last_name} ({$employe->emp_no})\n"; echo "Salaries:\n"; foreach ($employe->related('salaries') as $salary) { echo $salary->salary, "\n"; } echo "Departments:\n"; foreach ($employe->related('dept_emp') as $department) { echo $department->dept->dept_name, "\n"; } } ob_end_clean(); print_benchmark_result('NDB 2.3', 'Nette: 2.3.x');
$config->setAutoGenerateProxyClasses(TRUE); // we need __toString on DateTime, since UoW converts composite primary keys to string // (who the hell invented composite PKs :P) Type::overrideType(Type::DATE, 'Benchmark\\Types\\DateType'); Type::overrideType(Type::DATETIME, 'Benchmark\\Types\\DateTimeType'); // TODO you may want to change this? ;) $em = EntityManager::create(['driver' => 'pdo_mysql', 'user' => 'root', 'password' => '', 'dbname' => 'employees'], $config); $time = -microtime(TRUE); ob_start(); $qb = $em->createQueryBuilder()->from('Benchmark\\Entities\\Employee', 'e')->select('e')->innerJoin('e.salaries', 's')->addSelect('s')->innerJoin('e.affiliatedDepartments', 'd')->addSelect('d')->innerJoin('d.department', 'dd')->addSelect('dd')->setMaxResults(500)->getQuery(); $paginator = new Paginator($qb); foreach ($paginator->getIterator() as $emp) { /** @var Employee $emp */ // $output->writeln echo sprintf('%s %s (%d):', $emp->getFirstName(), $emp->getLastName(), $emp->getId()), PHP_EOL; // $output->writeln echo "\tSalaries:", PHP_EOL; foreach ($emp->getSalaries() as $salary) { // $output->writeln echo "\t\t", $salary->getAmount(), PHP_EOL; } // $output->writeln echo "\tDepartments:", PHP_EOL; foreach ($emp->getAffiliatedDepartments() as $department) { // $output->writeln echo "\t\t" . $department->getDepartment()->getName(), PHP_EOL; } } ob_end_clean(); print_benchmark_result('Doctrine2', 'Doctrine: ' . \Doctrine\Common\Version::VERSION);
<?php require __DIR__ . '/../print_benchmark_result.php'; if (@(!(include __DIR__ . '/vendor/autoload.php'))) { echo 'Install Nette using `composer install`'; exit(1); } require_once __DIR__ . '/loader.php'; date_default_timezone_set('Europe/Prague'); $cacheStorage = new Nette\Caching\Storages\FileStorage(__DIR__ . '/temp'); $connection = new Nette\Database\Connection('mysql:dbname=employees', 'employees', 'employees'); $structure = new Nette\Database\Structure($connection, $cacheStorage); $conventions = new Nette\Database\Conventions\DiscoveredConventions($structure); $context = new Nette\Database\Context($connection, $structure, $conventions, $cacheStorage); $time = -microtime(TRUE); ob_start(); $employees = new Model\Repository\EmployeeRepository($context); foreach ($employees->findAll()->limit(500) as $employee) { echo $employee->getFirstName(), ' ', $employee->getLastName(), ' (', $employee->getEmpNo(), ")\n"; echo 'Salaries:', "\n"; foreach ($employee->getSalaries() as $salary) { echo $salary->getSalary(), "\n"; } echo 'Departments:', "\n"; foreach ($employee->getDepartments() as $department) { echo $department->getName(), "\n"; } } ob_end_clean(); print_benchmark_result('YetORM');