rob-revisited/ide/tests/fixtures/profile/workload.php

8 lines
475 B
PHP

<?php
// A tiny program the profiler tests run under Xdebug to make real cachegrind / trace files.
function fib(int $n): int { return $n < 2 ? $n : fib($n - 1) + fib($n - 2); }
function allocate(int $n): array { $a = []; for ($i = 0; $i < $n; $i++) { $a[] = str_repeat('x', 100); } return $a; }
function work(): int { $s = 0; for ($i = 0; $i < 3000; $i++) { $s += $i % 7; } return $s; }
$keep = allocate(200);
echo fib(8), ' ', work(), ' ', count($keep), "\n";
unset($keep);