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