Test script:
#!/usr/bin/php
<?php
require __DIR__.'/../www/autoload.php';
$start = microtime(true);
$mem = memory_get_usage(true);
$resp = new \Symfony\Component\HttpFoundation\Response();
$elapsed = (microtime(true)-$start)*1000;
$used_mem = memory_get_usage(true)-$mem;
echo number_format($elapsed,2)." ms\n";
echo number_format($used_mem/1024,1)." KiB\n";
Output:
2.25 ms
256.0 KiB
The funny thing is, if I put it in a loop, the cost doesn't increase much:
$resp = [];
for($i=0; $i<100; ++$i) {
$resp[] = new \Symfony\Component\HttpFoundation\Response();
}
6.73 ms
512.0 KiB
But I only need one response, so that doesn't particularly matter.
Looking at the constructor for Response
, it barely does anything. It just initializes a handful of variables.
2ms is a significant portion of my response time, I'd really like to get that down if possible.