3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * SimpleXMLElement Introspection */ error_reporting(~0); $xml = '<document> <child> give <grandchild a1="v1" a2="v2"> me </grandchild> <grandchild> more </grandchild> sugar. </child> <child> </child> <single/> </document> '; $simple = new SimpleXMLElement($xml); /** * @param SimpleXMLElement $element * @return bool */ function simplexml_is_documentelement(SimpleXMLElement $element) { list($elementNode) = $element->xpath('.'); list($documentElement) = $element->xpath('/*'); return $elementNode == $element and $documentElement == $element; } $documentElement = $simple; $attributeList = $simple->child->grandchild->attributes(); $attributeListEmpty = $simple->child->attributes(); $attribute = $simple->child->grandchild['a1']; $suite = array( 'is_documentelement' => array('simplexml_is_documentelement', array( array(true, $documentElement), array(false, $documentElement->child), array(false, $documentElement->single), array(true, $simple->xpath('/*')[0]), array(true, $simple->simple->xpath('/*')[0]), array(false, $documentElement->child[0]), array(false, $documentElement->child->grandchild), array(false, $attribute), array(false, $attributeList), array(false, $attributeListEmpty), )), ); echo "Running tests with LIBXML ", LIBXML_DOTTED_VERSION, ":\n"; run_test_suite($suite); function run_test_suite(array $testsuite) { foreach ($testsuite as $caselabel => $testcasedef) { list($callback, $testcase) = $testcasedef; $stats[] = run_testcase($testcase, $callback, $caselabel); } echo "\n"; $stat['tests'] = 0; $stat['failures'] = 0; foreach ($stats as $singled) { $stat['tests'] += $singled['tests']; $stat['failures'] += $singled['failures']; echo $singled['messages']; } printf("Done %d tests with %d failures.", $stat['tests'], $stat['failures']); } function run_testcase(array $testcase, $callback, $label = null) { if ($label === null) $label = $callback; $stats['tests'] = 0; $stats['failures'] = 0; $messages = ''; foreach ($testcase as $i => $test) { list($expected, $subject, $testlabel) = $test + array(2 => "#$i"); $labeltest = $label . ' ' . $testlabel; ob_start(); $result = run_test($expected, $subject, $callback, $labeltest); $buffer = ob_get_clean(); echo $result ? '.' : 'F'; if ($buffer) { $messages .= sprintf("### %s ###\n", $labeltest); $messages .= $buffer; } $stats['tests']++; if (!$result) $stats['failures']++; } return $stats + array('messages' => $messages); } function run_test($expected, $subject, $callback, $label) { $actual = call_user_func($callback, $subject); if ($expected instanceof SimpleXMLElement and $actual instanceof SimpleXMLElement) { $result = $actual == $expected; } else { $result = $actual === $expected; } if (!$result) { $extra = ''; if ($subject instanceof SimpleXMLElement) { $extra = sprintf(' with %s', rtrim($subject->asXML())); } printf("FAILED to test %s%s.\n", $label, $extra); echo 'expected: ', var_dump($expected); echo 'actual:', var_dump($actual); } return $result; }

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.0130.01017.25
8.3.50.0110.00917.09
8.3.40.0100.01019.37
8.3.30.0080.00819.34
8.3.20.0100.00719.32
8.3.10.0060.00320.77
8.3.00.0030.00719.55
8.2.180.0090.01217.13
8.2.170.0070.01122.96
8.2.160.0060.00919.45
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0090.00626.16
8.2.120.0060.00321.30
8.2.110.0070.00420.97
8.2.100.0090.00318.53
8.2.90.0000.00918.38
8.2.80.0050.00319.41
8.2.70.0000.00818.13
8.2.60.0000.00918.42
8.2.50.0030.00618.13
8.2.40.0040.00418.72
8.2.30.0040.00418.23
8.2.20.0060.00618.21
8.2.10.0030.00518.23
8.2.00.0030.00918.22
8.1.280.0090.00925.92
8.1.270.0080.00024.66
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0090.00024.45
8.1.230.0000.00919.53
8.1.220.0030.00518.29
8.1.210.0090.00018.77
8.1.200.0070.00317.85
8.1.190.0040.00417.63
8.1.180.0040.00418.10
8.1.170.0000.00819.09
8.1.160.0040.00419.59
8.1.150.0050.00319.14
8.1.140.0040.00417.96
8.1.130.0040.00418.33
8.1.120.0050.00317.97
8.1.110.0050.00317.80
8.1.100.0000.00718.07
8.1.90.0040.00418.02
8.1.80.0040.00417.82
8.1.70.0040.00417.95
8.1.60.0000.00917.88
8.1.50.0040.00417.79
8.1.40.0080.00018.09
8.1.30.0060.00318.20
8.1.20.0030.00917.92
8.1.10.0040.00418.18
8.1.00.0000.00817.90
8.0.300.0080.00021.96
8.0.290.0040.00417.25
8.0.280.0050.00218.89
8.0.270.0000.00717.71
8.0.260.0030.00317.34
8.0.250.0070.00317.57
8.0.240.0040.00417.57
8.0.230.0040.00417.57
8.0.220.0030.00317.38
8.0.210.0000.00817.50
8.0.200.0030.00317.45
8.0.190.0040.00417.34
8.0.180.0040.00417.55
8.0.170.0040.00417.42
8.0.160.0040.00417.49
8.0.150.0000.00917.49
8.0.140.0000.00817.27
8.0.130.0030.00313.91
8.0.120.0030.00617.29
8.0.110.0000.00717.34
8.0.100.0030.00517.45
8.0.90.0020.00517.40
8.0.80.0090.00617.39
8.0.70.0040.00417.19
8.0.60.0080.00017.52
8.0.50.0090.00017.39
8.0.30.0070.01417.78
8.0.20.0080.01117.71
8.0.10.0030.00617.52
8.0.00.0110.00717.29
7.4.330.0030.00313.56
7.4.320.0000.00717.14
7.4.300.0030.00317.00
7.4.290.0030.00517.03
7.4.280.0000.00816.96
7.4.270.0040.00417.00
7.4.260.0000.00613.86
7.4.250.0090.00017.22
7.4.240.0040.00417.08
7.4.230.0050.00317.14
7.4.220.0060.01917.05
7.4.210.0090.01317.01
7.4.200.0000.00717.00
7.4.190.0040.00417.14
7.4.160.0140.00317.12
7.4.150.0120.01517.29
7.4.140.0130.00917.17
7.4.130.0110.00717.10
7.4.120.0030.01417.00
7.4.110.0170.00316.95
7.4.100.0150.00317.15
7.4.90.0000.01717.05
7.4.80.0120.01219.39
7.4.70.0100.00717.19
7.4.60.0060.01217.05
7.4.50.0030.00317.07
7.4.40.0130.00316.97
7.4.30.0030.01617.10
7.4.00.0090.00815.18
7.3.330.0000.00713.98
7.3.320.0050.00013.60
7.3.310.0050.00316.96
7.3.300.0030.00316.87
7.3.290.0080.00916.88
7.3.280.0050.01416.92
7.3.270.0060.01217.10
7.3.260.0090.01016.94
7.3.250.0100.01217.13
7.3.240.0060.01217.06
7.3.230.0040.01517.04
7.3.210.0140.00517.03
7.3.200.0060.01516.91
7.3.190.0110.00716.94
7.3.180.0100.00817.00
7.3.170.0100.00716.87
7.3.160.0090.00917.00
7.3.120.0100.00815.15
7.3.110.0050.01215.29
7.3.100.0110.00415.31
7.3.90.0050.00915.07
7.3.80.0090.00615.29
7.3.70.0070.00515.19
7.3.60.0070.01015.31
7.3.50.0070.00915.12
7.3.40.0080.00315.19
7.3.30.0060.00815.30
7.3.20.0070.00816.96
7.3.10.0120.00317.03
7.3.00.0050.00716.87
7.2.330.0100.00717.29
7.2.320.0060.01217.33
7.2.310.0060.01517.46
7.2.300.0080.01217.27
7.2.290.0100.01017.05
7.2.250.0030.01315.68
7.2.240.0080.01115.63
7.2.230.0050.00815.38
7.2.220.0060.00815.39
7.2.210.0050.00915.57
7.2.200.0020.01515.53
7.2.190.0090.00915.40
7.2.180.0040.01115.40
7.2.170.0040.00715.31
7.2.60.0060.01217.20
7.2.00.0070.00720.01
7.1.330.0080.00715.95
7.1.320.0110.00416.11
7.1.310.0060.00915.91
7.1.300.0060.00816.08
7.1.290.0050.00816.04
7.1.280.0020.01316.06
7.1.270.0050.00716.02
7.1.260.0050.00616.14
7.1.200.0060.01315.75
7.1.100.0030.00918.44
7.1.70.0000.01117.26
7.1.60.0110.01419.30
7.1.50.0110.01117.24
7.1.00.0000.06722.70
7.0.200.0040.00917.07
7.0.140.0030.07322.42
7.0.120.0100.07022.47
7.0.110.0100.06320.50
7.0.100.0170.06320.50
7.0.90.0130.07720.41
7.0.80.0130.08320.45
7.0.70.0170.07320.40
7.0.60.0100.07020.35
7.0.50.0130.08320.45
7.0.40.0030.08720.06
7.0.30.0200.05320.14
7.0.20.0130.05320.00
7.0.10.0100.07720.01
7.0.00.0130.07720.12
5.6.280.0030.07321.25
5.6.260.0130.04320.93
5.6.250.0130.07320.91
5.6.240.0070.05720.89
5.6.230.0100.08021.02
5.6.220.0070.08320.96
5.6.210.0130.07720.96
5.6.200.0200.07320.89
5.6.190.0100.07020.95
5.6.180.0070.08320.93
5.6.170.0170.07720.97
5.6.160.0070.08020.98
5.6.150.0070.08720.94
5.6.140.0070.04720.92
5.6.130.0030.09020.89
5.6.120.0100.08020.98
5.6.110.0070.08721.17
5.6.100.0100.08320.84
5.6.90.0070.07020.96
5.6.80.0000.05020.34
5.6.70.0100.04020.26
5.6.60.0000.04320.32
5.6.50.0030.04020.32
5.6.40.0100.03320.25
5.6.30.0100.03320.31
5.6.20.0100.03320.30
5.6.10.0030.06320.23
5.6.00.0000.04720.34
5.5.380.0030.07720.80
5.5.370.0070.08020.87
5.5.360.0070.04020.72
5.5.350.0070.08320.68
5.5.340.0100.04721.25
5.5.330.0070.07021.01
5.5.320.0070.07320.96
5.5.310.0070.06321.34
5.5.300.0130.05721.27
5.5.290.0100.07720.96
5.5.280.0070.08321.23
5.5.270.0070.07721.36
5.5.260.0070.05021.23
5.5.250.0130.06721.09
5.5.240.0030.04320.49
5.5.230.0000.04320.66
5.5.220.0070.03720.60
5.5.210.0030.03720.63
5.5.200.0030.04020.59
5.5.190.0030.04020.62
5.5.180.0100.05720.57
5.5.160.0130.06020.61
5.5.150.0000.04020.56
5.5.140.0030.04720.57
5.5.130.0070.07720.70
5.5.120.0070.04320.56
5.5.110.0030.07320.56
5.5.100.0030.08020.48
5.5.90.0030.06020.58
5.5.80.0070.08020.50
5.5.70.0030.04320.57
5.5.60.0000.04320.54
5.5.50.0030.08020.45
5.5.40.0130.02720.50
5.5.30.0000.07720.54
5.5.20.0070.04720.43
5.5.10.0070.03720.53
5.5.00.0170.06320.46
5.4.450.0130.06719.92
5.4.440.0100.08019.89
5.4.430.0130.06719.73
5.4.420.0070.08019.74
5.4.410.0100.07719.76
5.4.400.0030.04319.64
5.4.390.0030.04719.63
5.4.380.0070.04019.40
5.4.370.0030.03719.44
5.4.360.0000.04319.56
5.4.350.0130.03019.23
5.4.340.0130.04319.28
5.4.320.0000.04719.56
5.4.310.0000.04019.27
5.4.300.0000.04019.45
5.4.290.0030.07019.44
5.4.280.0030.07719.42
5.4.270.0000.08019.56
5.4.260.0130.05019.20
5.4.250.0030.05019.40
5.4.240.0030.04019.44
5.4.230.0070.07319.25
5.4.220.0000.04019.55
5.4.210.0070.03319.45
5.4.200.0000.04319.28
5.4.190.0130.04719.55
5.4.180.0000.08019.57
5.4.170.0070.03319.41
5.4.160.0100.03019.44
5.4.150.0070.03719.18
5.4.140.0000.08016.63
5.4.130.0130.03017.01
5.4.120.0070.06716.69
5.4.110.0030.05016.90
5.4.100.0030.03316.93
5.4.90.0030.04016.81
5.4.80.0030.03316.91
5.4.70.0030.04716.95
5.4.60.0000.03716.80
5.4.50.0030.03316.65
5.4.40.0070.06716.78
5.4.30.0030.07316.67
5.4.20.0000.08316.51
5.4.10.0030.07716.67
5.4.00.0070.05715.99
5.3.290.0070.03714.90
5.3.280.0000.08014.59
5.3.270.0030.04014.84
5.3.260.0000.04714.74
5.3.250.0030.03714.64
5.3.240.0000.04014.59
5.3.230.0030.04014.69
5.3.220.0000.06014.70
5.3.210.0000.04314.59
5.3.200.0070.03314.53
5.3.190.0030.03314.56
5.3.180.0030.03714.58
5.3.170.0000.03714.57
5.3.160.0000.06714.58
5.3.150.0070.05314.53
5.3.140.0030.04314.58
5.3.130.0070.08014.56
5.3.120.0130.07714.53
5.3.110.0030.07714.56
5.3.100.0030.07714.06
5.3.90.0000.08314.03
5.3.80.0130.06714.11
5.3.70.0000.07713.88
5.3.60.0030.07014.14
5.3.50.0070.07013.97
5.3.40.0100.06013.99
5.3.30.0130.06714.05
5.3.20.0100.04013.70
5.3.10.0030.06713.63
5.3.00.0000.08313.77
5.2.170.0070.06012.70
5.2.160.0070.06012.70
5.2.150.0070.05312.70
5.2.140.0030.04012.70
5.2.130.0030.05712.70
5.2.120.0100.02712.70
5.2.110.0030.05712.70
5.2.100.0030.06312.70
5.2.90.0070.05712.70
5.2.80.0070.03312.70
5.2.70.0030.06312.70
5.2.60.0070.06012.70
5.2.50.0000.06712.70
5.2.40.0000.06312.70
5.2.30.0070.03312.70
5.2.20.0030.05712.70
5.2.10.0100.05312.70
5.2.00.0000.06712.70
5.1.60.0070.05012.70
5.1.50.0030.05312.70
5.1.40.0000.05312.70
5.1.30.0030.05712.70
5.1.20.0030.06012.70
5.1.10.0000.06012.70
5.1.00.0000.03312.70
5.0.50.0000.05012.70
5.0.40.0030.04312.70
5.0.30.0030.06712.70
5.0.20.0030.04012.70
5.0.10.0030.04712.70
5.0.00.0030.05712.70
4.4.90.0000.03012.70
4.4.80.0030.03012.70
4.4.70.0030.03312.70
4.4.60.0030.03712.70
4.4.50.0030.03712.70
4.4.40.0000.05312.70
4.4.30.0100.01012.70
4.4.20.0000.03712.70
4.4.10.0000.03712.70
4.4.00.0070.05012.70
4.3.110.0000.03712.70
4.3.100.0000.03712.70
4.3.90.0000.03012.70
4.3.80.0030.05012.70
4.3.70.0000.02712.70
4.3.60.0030.03312.70
4.3.50.0000.03312.70
4.3.40.0000.05012.70
4.3.30.0000.02712.70
4.3.20.0000.03312.70
4.3.10.0000.03012.70
4.3.00.0070.03012.70

preferences:
58.79 ms | 401 KiB | 5 Q