Last active
September 7, 2026 09:37
-
-
Save staabm/ae867df5f19f88c56cd4de4418763fd3 to your computer and use it in GitHub Desktop.
microtime(true) is 10x faster than microtime()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ➜ phpstan-src git:(pr/6378) ✗ php -v | |
| PHP 8.5.10 (cli) (built: Aug 25 2026 21:09:32) (NTS) | |
| Copyright (c) The PHP Group | |
| Built by Homebrew | |
| Zend Engine v4.5.10, Copyright (c) Zend Technologies | |
| with Zend OPcache v8.5.10, Copyright (c), by Zend Technologies | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # hrtime(); | |
| string(9) "1,826,708" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # hrtime(); | |
| string(9) "1,837,125" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # hrtime(); | |
| string(9) "1,864,667" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # hrtime(true); | |
| string(9) "1,131,542" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # hrtime(true); | |
| string(9) "1,133,125" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # hrtime(true); | |
| string(9) "1,089,583" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # microtime(true); | |
| string(9) "1,838,334" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # microtime(true); | |
| string(9) "1,799,500" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # microtime(); | |
| string(10) "12,017,250" | |
| ➜ phpstan-src git:(pr/6378) ✗ php test.php # microtime(); | |
| string(10) "12,343,250" | |
| ➜ phpstan-src git:(pr/6378) ✗ cat test.php | |
| <?php | |
| $start = hrtime(true); | |
| for ($i=0; $i < 100000;$i++) { | |
| microtime(); | |
| } | |
| var_dump(number_format(hrtime(true)-$start)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment