Last active
August 19, 2025 09:36
-
-
Save OO00O0O/27ae1b5b70b4982455ea57b623c13aba to your computer and use it in GitHub Desktop.
Bench PHP hash algorithms speeds
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
| <?php declare(strict_types=1); | |
| echo "PHP Version: " . PHP_VERSION . "\n"; | |
| $times = []; | |
| foreach(hash_algos() as $algorithm) { | |
| $times[$algorithm] = 0.0; | |
| } | |
| for($i = 0; $i < 100_000; $i++) { | |
| $string = preg_replace_callback('/A/', fn () => '0123456789abcdefghijklmnopqrstuvwxyz'[mt_rand(0, 35)], str_repeat('A', 500)); | |
| foreach($times as $algorithm => &$time) { | |
| $start = microtime(true); | |
| hash($algorithm, $string); | |
| $time += microtime(true) - $start; | |
| } | |
| } | |
| asort($times); | |
| echo str_pad("Algorithm", 16) . "Time(ms)\n"; | |
| foreach($times as $algorithm => $time) { | |
| echo str_pad($algorithm, 16) . round($time * 1000, 2) . "\n"; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MacBook M4 Pro(2024) MacOS 15.6 (24G84)