View difference between Paste ID: 724v9rBZ and cT0gWuNH
SHOW: | | - or go back to the newest paste.
1
<?php
2
3
const EXECUTION_TIME = 5;
4
5
// <preparation>
6
$test = new class
7
{
8
    public function exists()
9
    {
10
        is_bool(true);
11
    }
12
};
13
// </preparation>
14
15
$timingStart = microtime(true);
16
$memoryStart = memory_get_usage(true);
17
$peakStart   = memory_get_peak_usage(true);
18
19
for ($iterations = 0; $iterations < PHP_INT_MAX; $iterations++) {
20
    // <code>
21
    $test->exists();
22
    // </code>
23
24
    // Timing control:
25
    if ($iterations % 1000 === 0 &&
26
        microtime(true) - $timingStart >= EXECUTION_TIME) {
27
        break;
28
    }
29
}
30
31
$timingDuration = microtime(true) - $timingStart;
32
$memoryEnd      = memory_get_usage(true);
33
$memoryUsage    = $memoryEnd - $memoryStart;
34
$peakEnd        = memory_get_peak_usage(true);
35
$peakUsage      = $peakEnd - $peakStart;
36
37
echo "\n\n";
38
39
printf("Cycles count   : %s\n", number_format($iterations, 0, '', '.'));
40
printf("Cycles by min. : %.2f\n", 60 / $timingDuration * $iterations);
41
printf("Total time     : %.2f sec.\n", $timingDuration);
42
printf("Memory usage   : %.2f MB (on end) - %.2f MB (on start) = %.2f MB (delta)\n",
43
    $memoryEnd / 1048576,
44
    $memoryStart / 1048576,
45
    $memoryUsage / 1048576);
46
printf("Memory peak    : %.2f MB (on end) - %.2f MB (on start) = %.2f MB (delta)\n\n\n",
47
    $peakEnd / 1048576,
48
    $peakStart / 1048576,
49
    $peakUsage / 1048576);