3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SafeBcryptWrapperPoC { private $staticKey; private $cost = 12; public function __construct( #[\SensitiveParameter] string $staticKey, int $cost = 12 ) { $this->staticKey = $staticKey; $this->cost = $cost; } /** * Generate password hashes here */ public function hash( #[\SensitiveParameter] string $password ): string { return \password_hash( $this->prehash($password), PASSWORD_BCRYPT, ['cost' => $this->cost] ); } /** * Verify password here */ public function verify( #[\SensitiveParameter] string $password, #[\SensitiveParameter] string $hash ): bool { return \password_verify( $this->prehash($password), $hash ); } /** * Pre-hashing with HMAC-SHA-512 here * * Note that this demo doesn't use libsodium, due to 3v4l limitations */ private function prehash( #[\SensitiveParameter] string $password ): string { return \base64_encode( \hash_hmac('sha512', $password, $this->staticKey, true) ); } } $staticKey = random_bytes(32); $hasher = new SafeBcryptWrapperPoC($staticKey); $example1 = str_repeat('A', 72); $example2 = $example1 . 'B'; $hash1 = password_hash($example1, PASSWORD_BCRYPT); $hash2 = $hasher->hash($example1); var_dump(password_verify($example2, $hash1)); var_dump($hasher->verify($example2, $hash2));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.10.0230.82518.97
8.3.140.0130.50918.39
8.3.130.0200.50517.67
8.3.120.0120.51216.64
8.3.110.0170.51116.59
8.3.100.0230.50416.59
8.3.90.0170.50917.36
8.3.80.0150.51016.67
8.3.70.0210.50617.69
8.3.60.0180.50516.64
8.3.50.0150.50917.59
8.3.40.0120.51319.22
8.3.30.0150.50818.40
8.3.20.0130.51418.21
8.3.10.0200.51017.58
8.3.00.0120.50918.22
8.2.260.0180.50616.45
8.2.250.0220.50416.36
8.2.240.0180.50417.25
8.2.230.0150.51216.34
8.2.220.0130.51216.66
8.2.210.0130.51317.51
8.2.200.0150.51416.50
8.2.190.0150.51316.59
8.2.180.0210.51017.30
8.2.170.0100.52317.53
8.2.160.0170.51117.38
8.2.150.0200.51217.50
8.2.140.0180.51817.27
8.2.130.0200.51718.26
8.2.120.0080.51918.23
8.2.110.0070.51818.29
8.2.100.0070.51919.32
8.2.90.0120.51417.44
8.2.80.0080.51617.56
8.2.70.0100.51717.32
8.2.60.0150.51118.24
8.2.50.0100.51717.47
8.2.40.0130.51317.38
8.2.30.0170.51118.19
8.2.20.0130.51718.29
8.2.10.0150.51217.47
8.2.00.0130.51417.35

preferences:
26.04 ms | 403 KiB | 5 Q