Skip to content

Commit

Permalink
Benchmark using preloaded classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Faugeron committed Mar 16, 2016
1 parent 3276580 commit c23d681
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Finally use [blackfire](https://blackfire.io/) to profile the request:

| Metric | Value |
|---------------------------------------------------|--------------|
| Requests per second | 1523.61#/sec |
| Time per request | 6.563ms |
| Time per request (across all concurrent requests) | 0.656ms |
| Requests per second | 1404.62#/sec |
| Time per request | 7.119ms |
| Time per request (across all concurrent requests) | 0.712ms |

> Benchmarks run with:
>
Expand Down
20 changes: 17 additions & 3 deletions bin/react.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@
use Symfony\Component\HttpFoundation\Request;

$loader = require __DIR__.'/../app/autoload.php';
include_once __DIR__.'/../var/bootstrap.php.cache';

// "optional" dependencies that weren't included
$toIgnore = array(
'Doctrine\Bundle\DoctrineCacheBundle\Acl\Model\AclCache',
);
// Preloading all classes
foreach ($loader->getClassMap() as $fqcn => $path) {
$isTest = (1 === preg_match('/Test/', $fqcn));
$isFixture = (1 === preg_match('/Fixture/', $fqcn));
$isIgnored = (true === in_array($fqcn, $toIgnore, true));
if ($isIgnored || $isTest || $isFixture) {
// Skipping test classes as PHPUnit will be missing, resulting in Fatal error
continue;
}
if (false === class_exists($fqcn) && false === interface_exists($fqcn) && false === trait_exists($fqcn)) {
$loader->loadClass($fqcn);
}
}

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();

$i = 0;

$app = function ($request, $response) use ($kernel) {
$sfRequest = Request::create(
$request->getPath(),
Expand Down

0 comments on commit c23d681

Please sign in to comment.