/**
 * @return \ProjectServiceContainer|\Symfony\Component\DependencyInjection\Container
 */
function symfonyFromConfig($config)
{
    $file = TEMP_DIR . '/container.php';
    $container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
    $container->addCompilerPass(new \Symfony\Component\DependencyInjection\Compiler\AutowirePass());
    $loader = new \Symfony\Component\DependencyInjection\Loader\YamlFileLoader($container, new \Symfony\Component\Config\FileLocator(TEMP_DIR));
    $loader->load(asfile('config.yml', $config));
    $container->compile();
    $dumper = new \Symfony\Component\DependencyInjection\Dumper\PhpDumper($container);
    file_put_contents($file, $dumper->dump());
    require_once $file;
    return new ProjectServiceContainer();
}
<?php

$file = __DIR__ . '/container_test5.php';
if (file_exists($file)) {
    require_once $file;
    $container = new ProjectServiceContainer();
} else {
    $container = new Symfony\Component\DependencyInjection\ContainerBuilder();
    $container->register('A', 'A');
    $ref = [new Symfony\Component\DependencyInjection\Reference('A')];
    $definition = new Symfony\Component\DependencyInjection\Definition('B', $ref);
    $definition->setScope('prototype');
    $container->setDefinition('B', $definition);
    $container->compile();
    $dumper = new Symfony\Component\DependencyInjection\Dumper\PhpDumper($container);
    file_put_contents($file, $dumper->dump());
}
//trigger autoloader
$a = $container->get('B');
unset($a);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $a = $container->get('B');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
 /**
  * Dump the service container into a plain PHP cached container file.
  *
  * @return void
  */
 protected function _cacheContainer()
 {
     $cacheFile = $this->_getCacheFile();
     $cacheName = pathinfo($cacheFile, PATHINFO_FILENAME);
     $dumper = new \Symfony\Component\DependencyInjection\Dumper\PhpDumper($this->getContainer());
     file_put_contents($cacheFile, $dumper->dump(array('class' => $cacheName)));
 }