3v4l.org

run code in 300+ PHP versions simultaneously
<?php function currentFloor(string $input): int { assert(! empty($input)); $positiveMatches = preg_match_all ('/\(/', $input); $negativeMatches = preg_match_all ('/\)/', $input); return $positiveMatches - $negativeMatches; } function basementPosition(string $input): int { $offset = 0; $length = strlen($input); while (currentFloor(substr($input, 0, $offset + 1 - $length)) !== -1) { $offset++; if ($offset > $length) { return -1; } } return $offset; } assert(currentFloor('(') === 1); assert(currentFloor(')') === -1); assert(currentFloor('()') === 0); assert(currentFloor('(()))))') === -3); var_dump(basementPosition(')')); var_dump(basementPosition('()())')); var_dump(basementPosition('(()))))')); var_dump(basementPosition('(((((')); assert(basementPosition('(()))))') === 5); assert(basementPosition('()())') === 5); assert(basementPosition(')') === 1); assert(basementPosition('(((((') === -1); $input = '()()(()()()(()()((()((()))((()((((()()((((()))()((((())(((((((()(((((((((()(((())(()()(()((()()(()(())(()((((()((()()()((((())((((((()(()(((()())(()((((()))())(())(()(()()))))))))((((((((((((()())()())())(())))(((()()()((((()(((()(()(()()(()(()()(()(((((((())(())(())())))((()())()((((()()((()))(((()()()())))(())))((((())(((()())(())(()))(()((((()())))())((()(())(((()((((()((()(())())))((()))()()(()(()))))((((((((()())((((()()((((()(()())(((((()(()())()))())(((()))()(()(()(()((((()(())(()))(((((()()(()()()(()(((())())(((()()(()()))(((()()(((())())(()(())())()()(())()()()((()(((()(())((()()((())()))((()()))((()()())((((()(()()(()(((()))()(()))))((()(((()()()))(()(((())()(()((()())(()(()()(()())(())()(((()(()())()((((()((()))))())()))((()()()()(())()())()()()((((()))))(()(((()()(((((((())()))()((((()((())()(()())(())()))(()(()())(((((((())))(((()))())))))()))())((())(()()((())()())()))))()((()()())(())((())((((()())())()()()(((()))())))()()))())(()()()(()((((((()()))())()))()(((()(((())((((()()()(()))())()()))))())()))())((())()())(((((())())((())())))(((())(((())(((((()(((((())(()(()())())(()(())(()))(()((((()))())()))))())))((()(()))))())))(((((())()))())()))))()))))(((()))()))))((()))((()((()(()(())()())))(()()()(())()))()((((())))))))(())(()((()()))(()))(()))(()((()))))))()()((((()()))()())()))))))()()()))(()((())(()))((()()()())()(((()((((())())))()((((()(()))))))())))()()())()))(()))))(()())()))))))((())))))))())()))()((())())))(()((()))()))(())))))(()))()())()()))((()(()))()()()()))))())()()))())(())()()))()))((()))))()()(()())))))()()()))((((()))()))))(()(())))(()())))((())())(()))()))))()())))()())()())))))))))()()))))())))((())((()))))())))(((()())))))))(()))()()))(()))()))))()())))))())((((()())))))))())))()()))))))))()))()))))()))))))(())))))))))())))))))))))))))())())((())))))))))()))((())))()))))))))())()(()))))))())))))()()()())()(()()()(()())(()))()()()(()())))())())))()))))())))))))()()()()())(())())()())()))))(()()()()()))))()))())())))((()())()())))()))()))))(()())))()))))))))(((()))()()))))))))))))))))))))(()))(()((()))())))())(()))(()(()(())))))()(()))()))()()))))))))))))()((()())(())())()(())))))())()())((()()))))(()()))))())()(())()))))))))))))))))))))()))(()(()())))))))()()((()))()))))))((())))()))))))))((()))())()()))())()()))((()))())))))))))))(()())()))(())((()(()()))(()())(())))()())(()(())()()))))()))()(()))))))(()))))))))))(()))())))))))))())))))())))(())))))()))))(())())))))))))()(()))))()())))())(()))()())))))))))))))())()()))))()))))))())))))()))))(())(()()()()((())()))())(()))((())()))())())(())(()()))))()))(())()()((())(())))(())))()))())))))))))()(((((())())))(())()))))(())))((()))()(((((((()))))()()))(())))))()(()))))(()()))()))())))))))(()())()))))))))())))(()))())()))(())()((())())()())())(()(()))))()))))))((()())(())()()(()())))()()))(())(())(()))())))()))(()))()()))((((()))))()))((()()()))))()))()))())))(()))()))))(())))()))())()(()))()())))())))))))())))())))()()))))))(()))())())))()))()()())())))))))))))))())))()))(()()))))())))())()(())))())))))))))))))))))()()())())))))()()()((()(()))()()(())()())()))()))))()()()))))))((()))))))))()(()(()((((((()()((()())))))))))))()))())))))((())())(()))())))())))))())()()())(())))())))()())())(())))))))()()(())))()))())))())())())()))))))))()))(()()()())())())))(())())))))))()()())()))))())))())()(())())))))))()())()))(()()(())())))()(()((()()((()()(((((())(()())()))(())()))(())))(())))))))()))()))((()))()))()))))))))()))))))))((()()())(()))(((()))(())))()))((())(((())))()())))())))))((())))))(())())((((((())())()(()))()(()((()())))((())()(()(()))))(())(()()())(())))())((()(((())())))(((()())())))())()(())())((((()()))))())((()))()()()()(())(((((((()()()((()))())(()())))(())())((((()()(()))))()((())))((())()))()(((()))())))()))((()(()))(())(()((((())((((()()(()()))(((())(()))))((((()(()))(())))))((()))(()))((()(((()(()))(()(()((()(())(()(()(()(()()((()))())(((())(()(()))))(()))()()))(())))(())()(((())(()))()((((()()))))())(()))))((())()((((()(((()))())())(((()))()())((())(())())(())()(())()(()()((((((()()))))()()(((()()))))()())()(((()(()))(()(()())(()(()))))(((((()(((())())))))(((((()((()()((())())((((((()(())(()()((()()()()()()()(()()))()(((()))()))(((((((())(((()((()())()((((())(((()(())))()((()(()()()((())((()())()))()))())))())((((((()))(()(()()()))(()((()(()(()))()((()(((()()()((())(((((())()(()))())())((()(())))(()(()())(())((())())())(((()()()(())))))())(()))))))()))))))())((()()()))((()((((((()))(((()((((()()()(((()))())()(()()(((()((()()()()())()()))()()()(()(())((()))))(()))())))))))()(()()(((((())()(()(((((()((()(()()())(()((((((((()((((((())()((((()()()((()((()((((((()))((())))))))())()))((()(()))()(()()(()((())((()()((((((((((((()())(()()()))((((()((((((())(()))())(()()((()()))()(((((((()((()()((((((()(((())))((())))((((((((()()(((((((())(((((()())(((())((())()((((()(((((((()(()(((()((((((()(((()(((((((((((()()((()()(()))((()()(((()(((())))((((())()(()(((())()(()(((())(((((((((((()))())))((((((())((()()((((()())())((((()()))((())(((((()(()()(()()()((())(()((()()((((()(((((()((()(()((((()())((((((()(((((()()(()(()((((())))(())(())(())((((()(()()((((()((((()()((()((((((())))(((((()))))()))(()((((((((()(((())())(((())))(()(()((())(((()((()()(((((()((()()(((())()(()))(((((((())(()(((((()))((()((()((()))(())())((((()((((())()(()))(((()(((((((((((((((())(((((((((()))(((()(()()()()((((((()((())()((((((((()(())(((((((((((()(()((())()((()()(()(()()((((()()((())(()((()()(()()((((()(((((((())))((((())(())()(((()()((()()((((()((()(((()((())(((()()()((((()((((()()(()(()((((((((())(()(((((())(()())(((((((()())()(()((((()((())(()()())((((()()(((()((((())(())(()()(((((((((()()))()(((())(()(()((((((())(()()())(()))()()(((()(((()((())(()(((((((()(()(()((()(((((()(()((()(()((((((()((((()()((((()(((()((())(()(()((()()((((()()(())()(())(((())(()((((((((()())(((((((((()(())()((((())))()))()()(((((()()((((((())(()()(((()(()(((((((()(()(((((((())(())((((()((()(())))((((()()())(()))((()())((((()(((((()(()(())(()(()()())(((((()(((((()((((()()((((((((()()))(()((((((())((((())()(()(((()()()(((()(()(())(())(((((()(())())((((())(())(()(((()(((((())((((())())((()(((((((()(((())(()(()))(((((((((()((()((()()(()((((())(((()((())((((())(()(((()(((()(()((((()(((())(()(((()(()()(()(()((()()(()())(())())((()(()(((()(((()(((()()(((((((((()(((((((((()()(((()(((()())((((()(()(((()()()((())((((((((((())(()(((()((((()())((((()((()))(((()()()(((((()(((((((())((()())(()((((())((((((((())(()((()((((((((((()()((()((()()))(((()())()())()(((()())()()(()(()(((((((())()))(())()))())()()((())()((()((((()((()((())(((((()((((((()(())))(()))())(((()))((()()(()(((()))((((())()(((()))))()(()(())()(((((())(()(()(())(())()((()()()((((()(())((()())(()(()))(()(()(()()(())()()(()((())()((()))))()))((()(()()()()((()())(()))())()(()(((((((((())())((()((()((((((())()((((())(((())((()(()()()((())(()((())(((()((((()()((()(()(((((())()))()((((((()))((())(((()()))(((())(())()))(((((((())(())())()(())(((((()))()((()))()(()()((()()()()()())((((((('; var_dump(currentFloor($input)); var_dump(basementPosition($input));

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.0000.01518.43
8.3.50.0070.01222.00
8.3.40.0150.00019.13
8.3.30.0070.00719.19
8.3.20.0090.00020.30
8.3.10.0070.00021.73
8.3.00.0040.00419.79
8.2.180.0110.00718.54
8.2.170.0030.01222.96
8.2.160.0120.00620.47
8.2.150.0050.00324.18
8.2.140.0030.00524.66
8.2.130.0050.00326.16
8.2.120.0070.00020.94
8.2.110.0070.01121.12
8.2.100.0040.00717.76
8.2.90.0030.00618.22
8.2.80.0040.00417.97
8.2.70.0000.00918.00
8.2.60.0000.01317.93
8.2.50.0040.00418.07
8.2.40.0080.00022.14
8.2.30.0040.00420.61
8.2.20.0040.00417.87
8.2.10.0050.00218.08
8.2.00.0030.00618.07
8.1.280.0120.00325.92
8.1.270.0090.00920.53
8.1.260.0070.00726.35
8.1.250.0030.00528.09
8.1.240.0060.00322.61
8.1.230.0070.00320.97
8.1.220.0030.00617.74
8.1.210.0060.00319.01
8.1.200.0070.00317.47
8.1.190.0050.00317.38
8.1.180.0030.00518.10
8.1.170.0000.00818.71
8.1.160.0040.00420.69
8.1.150.0070.00018.87
8.1.140.0050.00319.53
8.1.130.0000.00717.79
8.1.120.0070.00017.57
8.1.110.0030.00617.72
8.1.100.0030.00517.59
8.1.90.0090.00317.54
8.1.80.0080.00017.69
8.1.70.0070.00017.48
8.1.60.0040.00417.78
8.1.50.0040.00417.64
8.1.40.0000.00817.59
8.1.30.0050.00317.73
8.1.20.0030.00617.90
8.1.10.0030.00617.82
8.1.00.0090.00017.75
8.0.300.0000.00720.02
8.0.290.0040.00417.13
8.0.280.0070.00018.39
8.0.270.0070.00017.38
8.0.260.0000.00817.40
8.0.250.0030.00317.06
8.0.240.0040.00417.21
8.0.230.0000.00817.10
8.0.220.0040.00417.19
8.0.210.0000.00717.20
8.0.200.0030.00317.16
8.0.190.0110.00017.11
8.0.180.0050.00317.15
8.0.170.0040.00417.24
8.0.160.0000.00817.14
8.0.150.0040.00417.11
8.0.140.0080.00317.12
8.0.130.0050.00013.64
8.0.120.0040.00417.15
8.0.110.0000.00717.11
8.0.100.0030.00517.02
8.0.90.0000.00816.98
8.0.80.0060.01017.12
8.0.70.0040.00417.22
8.0.60.0000.00817.21
8.0.50.0040.00417.02
8.0.30.0140.00817.27
8.0.20.0100.01117.45
8.0.10.0050.00317.10
8.0.00.0090.00916.84
7.4.330.0000.03516.88
7.4.320.0000.03816.95
7.4.300.0030.03416.83
7.4.290.0030.03416.68
7.4.280.0030.03516.91
7.4.270.0040.03516.96
7.4.260.0000.03816.94
7.4.250.0070.03316.88
7.4.240.0050.03416.93
7.4.230.0070.03116.61
7.4.220.0130.05316.66
7.4.210.0130.08916.98
7.4.200.0060.03817.03
7.4.160.0240.06116.73
7.4.150.0030.11417.40
7.4.140.0160.07817.86
7.4.130.0110.06316.76
7.4.120.0100.06116.79
7.4.110.0190.05816.86
7.4.100.0060.06516.64
7.4.90.0030.06316.86
7.4.80.0070.06319.39
7.4.70.0100.05616.84
7.4.60.0070.05816.98
7.4.50.0070.05416.50
7.4.40.0170.09316.64
7.4.30.0100.05616.89
7.4.10.0070.08215.20
7.4.00.0080.07015.25
7.3.330.0030.03613.68
7.3.320.0000.04013.69
7.3.310.0000.04116.53
7.3.300.0030.03716.72
7.3.290.0090.06716.63
7.3.280.0110.06116.63
7.3.270.0060.06017.40
7.3.260.0030.06316.68
7.3.250.0110.07416.76
7.3.240.0120.06016.77
7.3.230.0130.05616.87
7.3.210.0060.10316.70
7.3.200.0120.08016.80
7.3.190.0100.05816.66
7.3.180.0120.06416.73
7.3.170.0070.10016.82
7.3.160.0100.06916.71
7.3.130.0100.07815.32
7.3.120.0050.07715.26
7.3.110.0070.08215.26
7.3.100.0060.05315.12
7.3.90.0020.06815.18
7.3.80.0050.05415.21
7.3.70.0070.06815.11
7.3.60.0030.06814.96
7.3.50.0020.05714.99
7.3.40.0050.05415.07
7.3.30.0050.06714.99
7.3.20.0050.05516.72
7.3.10.0030.07116.96
7.3.00.0030.05516.74
7.2.330.0100.06716.76
7.2.320.0090.09816.90
7.2.310.0100.05317.05
7.2.300.0070.05617.00
7.2.290.0130.05616.84
7.2.260.0100.08015.45
7.2.250.0060.07415.40
7.2.240.0080.06615.40
7.2.230.0100.06215.36
7.2.220.0050.06315.35
7.2.210.0020.05415.28
7.2.200.0050.04915.19
7.2.190.0070.04915.07
7.2.180.0070.05415.19
7.2.170.0050.05015.29
7.2.160.0100.07715.02
7.2.150.0030.05517.20
7.2.140.0000.05517.21
7.2.130.0000.05817.00
7.2.120.0070.05316.86
7.2.110.0000.05517.27
7.2.100.0030.05717.13
7.2.90.0070.04917.19
7.2.80.0030.05817.00
7.2.70.0070.07417.01
7.2.60.0020.06417.15
7.2.50.0030.05817.08
7.2.40.0030.05417.10
7.2.30.0030.05217.11
7.2.20.0030.05916.98
7.2.10.0030.05417.23
7.2.00.0050.05018.40
7.1.330.0080.07216.11
7.1.320.0070.08215.95
7.1.310.0030.09115.98
7.1.300.0030.07815.85
7.1.290.0050.06916.00
7.1.280.0050.07815.89
7.1.270.0030.08715.96
7.1.260.0050.07315.94
7.1.250.0030.06815.85
7.1.240.0000.09116.10
7.1.230.0070.10916.09
7.1.220.0070.09816.16
7.1.210.0030.07315.98
7.1.200.0050.06415.99
7.1.190.0030.09415.85
7.1.180.0100.09516.16
7.1.170.0070.06816.05
7.1.160.0030.08416.09
7.1.150.0070.06915.96
7.1.140.0030.06915.83
7.1.130.0070.06616.04
7.1.120.0030.06615.98
7.1.110.0100.06616.06
7.1.100.0050.07417.09
7.1.90.0000.07416.04
7.1.80.0030.07116.16
7.1.70.0030.07116.61
7.1.60.0050.09117.63
7.1.50.0100.09116.59
7.1.40.0030.07815.80
7.1.30.0070.12116.05
7.1.20.0070.07015.95
7.1.10.0030.07215.76
7.1.00.0050.11219.28
7.0.330.0030.07815.39
7.0.320.0000.08315.57
7.0.310.0070.07115.58
7.0.300.0030.07015.66
7.0.290.0030.06515.71
7.0.280.0100.06315.70
7.0.270.0070.06615.69
7.0.260.0030.07615.51
7.0.250.0030.07015.64
7.0.240.0070.07715.80
7.0.230.0030.07315.65
7.0.220.0030.06715.69
7.0.210.0030.07315.34
7.0.200.0050.09316.25
7.0.190.0070.06615.58
7.0.180.0030.09615.51
7.0.170.0100.11315.54
7.0.160.0000.08215.62
7.0.150.0000.08315.71
7.0.140.0030.06715.53
7.0.130.0070.08015.72
7.0.120.0030.07015.78
7.0.110.0000.07015.80
7.0.100.0280.07617.88
7.0.90.0130.09517.79
7.0.80.0100.10817.87
7.0.70.0100.12117.79
7.0.60.0050.11217.77
7.0.50.0020.10018.14
7.0.40.0080.09316.83
7.0.30.0020.09416.88
7.0.20.0070.08616.82
7.0.10.0070.10716.94
7.0.00.0070.10316.91
5.6.400.0000.00914.02
5.6.390.0040.00414.29
5.6.380.0000.00813.92
5.6.370.0070.00314.38
5.6.360.0060.00613.99
5.6.350.0040.01113.80
5.6.340.0090.00314.37
5.6.330.0060.00614.14
5.6.320.0030.00714.03
5.6.310.0050.00514.31
5.6.300.0040.00714.02
5.6.290.0000.01214.16
5.6.280.0000.01314.11
5.6.270.0000.01114.32
5.6.260.0040.01114.11
5.6.250.0090.04017.46
5.6.240.0130.03817.40
5.6.230.0030.03617.27
5.6.220.0120.03817.15
5.6.210.0080.04017.41
5.6.200.0020.03217.62
5.6.190.0070.02217.59
5.6.180.0080.03117.61
5.6.170.0100.04617.44
5.6.160.0060.04517.68
5.6.150.0070.04317.61
5.6.140.0080.04217.72
5.6.130.0080.04217.62
5.6.120.0070.04217.63
5.6.110.0030.04217.62
5.6.100.0020.05117.67
5.6.90.0130.02017.52
5.6.80.0050.04117.22
5.6.70.0100.03717.22
5.6.60.0110.04317.13
5.6.50.0050.04417.23
5.6.40.0050.03417.34
5.6.30.0040.02517.07
5.6.20.0070.02517.25
5.6.10.0070.04317.22
5.6.00.0100.01717.28
5.5.380.0050.04817.20
5.5.370.0070.03717.22
5.5.360.0080.04317.10
5.5.350.0120.02517.22
5.5.340.0120.03717.67
5.5.330.0050.03517.74
5.5.320.0060.04317.45
5.5.310.0070.02917.47
5.5.300.0110.02617.68
5.5.290.0090.03417.44
5.5.280.0050.03917.47
5.5.270.0070.04017.36
5.5.260.0080.03817.48
5.5.250.0080.03717.30
5.5.240.0080.03616.97
5.5.230.0050.04516.90
5.5.220.0130.02517.16
5.5.210.0100.02217.12
5.5.200.0030.02816.98
5.5.190.0050.02817.06
5.5.180.0050.04316.89
5.5.170.0030.00913.91
5.5.160.0080.04517.24
5.5.150.0030.04017.09
5.5.140.0100.04217.25
5.5.130.0050.04117.20
5.5.120.0030.02517.01
5.5.110.0080.03017.18
5.5.100.0080.04017.09
5.5.90.0080.03517.13
5.5.80.0050.02617.05
5.5.70.0130.03717.04
5.5.60.0070.03817.19
5.5.50.0080.02817.06
5.5.40.0070.04017.13
5.5.30.0050.02717.19
5.5.20.0040.04616.98
5.5.10.0070.04116.99
5.5.00.0090.03916.98

preferences:
49.56 ms | 401 KiB | 5 Q