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() |
| 8 | + | |
| 9 | - | {
|
| 9 | + | |
| 10 | - | is_bool(true); |
| 10 | + | |
| 11 | $timingStart = microtime(true); | |
| 12 | $memoryStart = memory_get_usage(true); | |
| 13 | $peakStart = memory_get_peak_usage(true); | |
| 14 | ||
| 15 | for ($iterations = 0; $iterations < PHP_INT_MAX; $iterations++) {
| |
| 16 | // <code> | |
| 17 | if (method_exists($test, 'exists')) {
| |
| 18 | $test->exists() | |
| 19 | } | |
| 20 | // </code> | |
| 21 | - | $test->exists(); |
| 21 | + | |
| 22 | // Timing control: | |
| 23 | if ($iterations % 1000 === 0 && | |
| 24 | microtime(true) - $timingStart >= EXECUTION_TIME) {
| |
| 25 | break; | |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 29 | $timingDuration = microtime(true) - $timingStart; | |
| 30 | $memoryEnd = memory_get_usage(true); | |
| 31 | $memoryUsage = $memoryEnd - $memoryStart; | |
| 32 | $peakEnd = memory_get_peak_usage(true); | |
| 33 | $peakUsage = $peakEnd - $peakStart; | |
| 34 | ||
| 35 | echo "\n\n"; | |
| 36 | ||
| 37 | printf("Cycles count : %s\n", number_format($iterations, 0, '', '.'));
| |
| 38 | printf("Cycles by min. : %.2f\n", 60 / $timingDuration * $iterations);
| |
| 39 | printf("Total time : %.2f sec.\n", $timingDuration);
| |
| 40 | printf("Memory usage : %.2f MB (on end) - %.2f MB (on start) = %.2f MB (delta)\n",
| |
| 41 | $memoryEnd / 1048576, | |
| 42 | $memoryStart / 1048576, | |
| 43 | $memoryUsage / 1048576); | |
| 44 | printf("Memory peak : %.2f MB (on end) - %.2f MB (on start) = %.2f MB (delta)\n\n\n",
| |
| 45 | $peakEnd / 1048576, | |
| 46 | $peakStart / 1048576, | |
| 47 | $peakUsage / 1048576); |