3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * A simple user account database */ class UserAccountDatabase { private $data = []; /** * Save a user account * * @param string $username * @param string $password * @return void * @throws Exception */ public function saveAccount($username, $password) { if ($this->getAccount($username) !== null) { throw new \Exception('Username already exists in database.'); } $this->data[$username] = $password; } /** * Get a user account by username * * @param string $username * @return array|null */ public function getAccount($username) { return isset($this->data[$username]) ? $this->data[$username] : null; } /** * Delete a user account by username * * @param string $username * @return void */ public function deleteAccount($username) { unset($this->data[$username]); } } /** * You must implement this interface */ interface UserAccountManagerInterface { /** * @param UserAccountDatabase $db */ public function __construct(UserAccountDatabase $db); /** * Allow a user to create an account. Should return true if account creation * was successful and false otherwise. * * @param string $username * @param string $password * @return bool */ public function create($username, $password); /** * Allow a user to authenticate using the same username and password that * they used when creating their account. Should return true if the account * exists and the password matches or false otherwise. * * @param string $username * @param string $password * @return bool */ public function authenticate($username, $password); } class UserAccountManager implements UserAccountManagerInterface { private $db; public function __construct(UserAccountDatabase $db) { $this->db = $db; } public function create($username, $password) { try { $this->db->saveAccount($username, $password); return true; } catch (Exception $e) { return false; } } public function authenticate($username, $password) { $stored_pass = $this->db->getAccount($username); if ($stored_pass === null) { return false; } return $password === $stored_pass; } } /////////////////////////// $input = fopen("php://memory", "rw"); $data = '[ [ ["abe","12345"], ["ben","67890"], ["ben","67890"] ], [ ["abe","12345"], ["ben","67890"], ["ben","67890"], ["carla","12345"] ] ]'; fwrite($input, $data); fseek($input, 0); // Setup Streams //$input = fopen("php://stdin", "r"); $output = fopen("php://stdout","w"); // Input (JSON) $arguments = json_decode(trim(stream_get_contents($input)), true, 16); //var_dump($arguments); die(); $db = new UserAccountDatabase(); $manager = new UserAccountManager($db); $result = []; // Create Accounts foreach ($arguments[0] as $account) { $result[0][] = call_user_func_array([$manager, 'create'], $account); } // Authenticate Accounts foreach ($arguments[1] as $account) { $result[1][] = call_user_func_array([$manager, 'authenticate'], $account); } // Output (JSON) fwrite($output, json_encode($result)); fclose($output);

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.3.60.0150.00016.75
8.3.50.0210.00921.21
8.3.40.0110.00418.79
8.3.30.0140.00018.80
8.3.20.0050.00320.27
8.3.10.0000.00823.52
8.3.00.0080.00023.70
8.2.180.0100.00718.54
8.2.170.0070.01122.96
8.2.160.0070.01020.35
8.2.150.0070.00725.66
8.2.140.0080.00024.66
8.2.130.0040.00419.54
8.2.120.0030.00626.35
8.2.110.0070.00319.45
8.2.100.0060.00617.84
8.2.90.0110.00019.17
8.2.80.0090.00017.97
8.2.70.0060.00317.75
8.2.60.0040.00418.03
8.2.50.0040.00418.07
8.2.40.0000.00822.22
8.2.30.0040.00420.59
8.2.20.0000.00817.81
8.2.10.0040.00418.05
8.2.00.0060.00318.17
8.1.280.0170.00325.92
8.1.270.0000.00923.87
8.1.260.0080.00028.09
8.1.250.0030.00528.09
8.1.240.0060.00321.34
8.1.230.0060.00617.46
8.1.220.0040.00417.79
8.1.210.0000.00818.77
8.1.200.0040.00417.48
8.1.190.0000.00817.23
8.1.180.0000.00818.10
8.1.170.0040.00418.53
8.1.160.0000.00720.81
8.1.150.0070.00018.98
8.1.140.0000.00819.60
8.1.130.0000.00717.83
8.1.120.0000.00717.52
8.1.110.0040.00417.39
8.1.100.0040.00417.40
8.1.90.0000.00717.41
8.1.80.0040.00417.42
8.1.70.0050.00217.41
8.1.60.0040.00417.64
8.1.50.0000.00817.54
8.1.40.0030.00517.50
8.1.30.0040.00417.72
8.1.20.0080.00017.60
8.1.10.0000.00817.48
8.1.00.0040.00417.55
8.0.300.0040.00418.77
8.0.290.0070.00016.88
8.0.280.0000.00718.48
8.0.270.0070.00017.29
8.0.260.0040.00417.36
8.0.250.0040.00417.07
8.0.240.0030.00317.00
8.0.230.0030.00317.10
8.0.220.0040.00417.09
8.0.210.0080.00017.00
8.0.200.0030.00317.04
8.0.190.0000.00917.15
8.0.180.0070.00017.07
8.0.170.0000.01116.99
8.0.160.0000.00717.20
8.0.150.0030.00517.06
8.0.140.0040.00417.00
8.0.130.0030.00313.53
8.0.120.0000.00717.07
8.0.110.0000.00716.98
8.0.100.0040.00417.01
8.0.90.0070.00016.85
8.0.80.0040.01217.13
8.0.70.0090.00017.12
8.0.60.0000.00717.01
8.0.50.0040.00417.07
8.0.30.0080.01117.21
8.0.20.0110.01217.40
8.0.10.0040.00417.24
8.0.00.0090.00916.82
7.4.330.0050.00016.74
7.4.320.0030.00316.50
7.4.300.0000.00616.66
7.4.290.0030.00316.54
7.4.280.0020.00816.64
7.4.270.0000.00616.55
7.4.260.0040.00416.65
7.4.250.0040.00416.42
7.4.240.0060.00116.58
7.4.230.0030.00316.46
7.4.220.0100.01016.64
7.4.210.0090.00616.69
7.4.200.0070.00016.72
7.4.160.0100.01316.58
7.4.150.0050.01317.40
7.4.140.0090.01217.86
7.4.130.0140.00716.55
7.4.120.0120.00916.63
7.4.110.0000.01816.70
7.4.100.0130.00616.55
7.4.90.0100.00716.66
7.4.80.0100.01319.39
7.4.70.0030.01316.62
7.4.60.0130.00316.57
7.4.50.0060.00816.71
7.4.40.0200.00616.60
7.4.30.0110.01016.75
7.4.00.0100.00615.26
7.3.330.0060.00013.39
7.3.320.0000.00513.40
7.3.310.0030.00316.53
7.3.300.0000.00616.41
7.3.290.0030.00316.35
7.3.280.0060.01016.50
7.3.270.0120.00617.40
7.3.260.0100.00716.45
7.3.250.0090.01016.55
7.3.240.0090.01216.57
7.3.230.0140.00416.68
7.3.210.0100.01016.68
7.3.200.0060.01119.39
7.3.190.0040.01216.47
7.3.180.0130.00316.53
7.3.170.0080.00916.41
7.3.160.0120.00416.57
7.2.330.0100.00716.57
7.2.320.0090.01216.81
7.2.310.0060.01216.72
7.2.300.0120.01216.53
7.2.290.0060.01016.85
7.2.60.0060.00617.10
7.2.00.0000.01419.57
7.1.200.0040.00415.87
7.1.100.0000.01118.07
7.1.70.0020.00517.27
7.1.60.0040.01119.21
7.1.50.0120.00616.77
7.1.00.0030.07722.28
7.0.200.0100.00016.47
7.0.90.0070.07319.97
7.0.80.0470.03720.04
7.0.70.0300.07719.90
7.0.60.0430.06719.84
7.0.50.0530.04720.35
7.0.40.0200.07720.10
7.0.30.0030.07319.96
7.0.20.0130.06720.17
7.0.10.0030.06720.09
7.0.00.0130.04020.00
5.6.280.0030.05320.95
5.6.230.0070.08020.61
5.6.220.0030.08020.61
5.6.210.0070.07020.61
5.6.200.0100.08021.20
5.6.190.0170.07321.13
5.6.180.0130.07321.13
5.6.170.0030.08320.96
5.6.160.0030.08320.95
5.6.150.0030.08321.14
5.6.140.0200.07321.08
5.6.130.0170.07721.06
5.6.120.0100.07021.10
5.6.110.0070.05021.05
5.6.100.0070.04020.96
5.6.90.0100.03721.06
5.6.80.0130.03320.45
5.6.70.0100.03720.46
5.6.60.0030.03720.33
5.6.50.0100.03020.49
5.6.40.0030.04720.52
5.6.30.0030.04020.38
5.6.20.0000.05020.45
5.6.10.0070.03720.31
5.6.00.0000.03720.53
5.5.370.0030.06020.44
5.5.360.0100.05020.36
5.5.350.0070.06320.48
5.5.340.0100.08020.82
5.5.330.0070.08320.94
5.5.320.0100.06720.79
5.5.310.0170.05320.67
5.5.300.0100.06020.82
5.5.290.0130.07320.89
5.5.280.0130.07720.95
5.5.270.0030.04720.77
5.5.260.0030.05020.80
5.5.250.0330.02020.58
5.5.240.0000.04720.27
5.5.230.0000.04320.28
5.5.220.0030.04020.19
5.5.210.0000.04320.21
5.5.200.0030.04020.29
5.5.190.0030.04020.01
5.5.180.0030.03720.15
5.5.160.0070.03720.26
5.5.150.0030.04020.24
5.5.140.0070.04320.20
5.5.130.0070.03720.23
5.5.120.0000.03720.23
5.5.110.0000.04320.13
5.5.100.0030.04020.04
5.5.90.0030.03720.06
5.5.80.0070.03720.11
5.5.70.0070.04720.11
5.5.60.0070.03720.16
5.5.50.0070.03720.11
5.5.40.0070.03319.98
5.5.30.0070.03320.11
5.5.20.0070.03720.17
5.5.10.0070.03720.00
5.5.00.0030.04019.99

preferences:
46.43 ms | 401 KiB | 5 Q