<?php
printf("test.php: php %s, phar-api %s\n", PHP_VERSION, PharData::apiVersion());
class Metrics
{
public $steps = array();
public function emit($what, $usage) {
static $prev;
static $beat = 0;
if ($prev) {
$this->steps[$beat] = $usage - $prev;
}
printf("[%s %05d] %s: %s\n", PHP_VERSION, ++$beat, $what, $prev ? sprintf('%d %+d', $usage, $usage - $prev): $usage);
$prev = $usage;
}
public function tick($what) {
$this->emit($what, memory_get_usage());
}
public function summary() {
$steps = $this->steps;
$count = count($steps);
$steps[] = null;
for ($i = 1; $i < $count;) {
$v = $steps[$i];
for ($j = $i + 1; $j <= $count; $j++) {
$w = $steps[$j];
if ($w !== $v) {
$c = $i === $j - 1 ? 1 : $j - $i;
$cc[$v] = (isset($cc[$v]) ? $cc[$v] : 0) + $c;
printf(
"%-8s %-2s %+d %d\n",
1 === $c ? $i : sprintf('%d-%d', $i, $j - 1),
1 === $c ? '' : $j - $i,
$v,
$cc[$v]
);
$i = $j;
break;
}
}
}
}
}
$metrics = new Metrics();
$metrics->tick('start');
function phar_tick()
{
static $i = 0;
$path = sprintf('%s/%d.tar', sys_get_temp_dir(), $i); # new filesnames each: https://3v4l.org/lGa2n
$phar = new PharData($path);
$phar->addEmptyDir('test');
unset($phar);
unlink($path);
}
for ($i = 0; $i < 100; $i++) {
phar_tick();
$metrics->tick('after');
}
gc_collect_cycles();
$metrics->tick('end');
$metrics->summary();
preferences:
38.55 ms | 402 KiB | 5 Q