Test script:
<?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";
Conclusion:
2.25 ms
256.0 KiB
The funny thing is, if I put it in a loop, the cost did not increase:
$resp = [];
for($i=0; $i<100; ++$i) {
$resp[] = new \Symfony\Component\HttpFoundation\Response();
}
6.73 ms
512.0 KiB
But I need only one answer, so that doesn't really matter.
Looking at the constructor for Response, he does nothing. It simply initializes several variables.
2ms is a significant part of my response time, I would really like it to be possible.
source
share