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, reset(($simple->xpath('/*')))), array(true, reset(($simple->simple->xpath('/*')))), 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.0090.00618.81
8.3.50.0090.00822.17
8.3.40.0090.00919.21
8.3.30.0110.00419.46
8.3.20.0090.00020.63
8.3.10.0080.00023.98
8.3.00.0000.00921.21
8.2.180.0160.00317.25
8.2.170.0160.00622.96
8.2.160.0040.01120.89
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0080.00026.16
8.2.120.0030.00521.13
8.2.110.0030.00622.70
8.2.100.0130.00018.18
8.2.90.0000.00819.84
8.2.80.0030.00518.13
8.2.70.0060.00318.13
8.2.60.0080.00318.53
8.2.50.0060.00318.07
8.2.40.0000.00818.72
8.2.30.0030.00718.68
8.2.20.0000.00818.15
8.2.10.0000.00818.48
8.2.00.0030.00518.21
8.1.280.0080.00825.92
8.1.270.0040.00424.20
8.1.260.0040.00426.35
8.1.250.0090.00028.09
8.1.240.0030.00624.40
8.1.230.0090.00319.60
8.1.220.0060.00318.15
8.1.210.0040.00418.77
8.1.200.0100.00017.85
8.1.190.0040.00417.73
8.1.180.0000.00818.10
8.1.170.0080.00018.91
8.1.160.0040.00422.43
8.1.150.0070.00019.03
8.1.140.0040.00417.94
8.1.130.0000.00718.20
8.1.120.0030.00517.98
8.1.110.0030.00617.96
8.1.100.0050.00217.99
8.1.90.0000.00717.99
8.1.80.0040.00417.99
8.1.70.0040.00417.92
8.1.60.0000.00817.94
8.1.50.0000.00817.80
8.1.40.0000.00817.88
8.1.30.0030.00818.17
8.1.20.0060.00318.16
8.1.10.0080.00017.97
8.1.00.0030.00618.02
8.0.300.0090.00018.77
8.0.290.0000.00717.25
8.0.280.0000.00818.86
8.0.270.0000.00717.71
8.0.260.0040.00217.66
8.0.250.0030.00317.51
8.0.240.0030.00617.34
8.0.230.0070.00017.47
8.0.220.0030.00317.33
8.0.210.0040.00317.32
8.0.200.0030.00317.39
8.0.190.0080.00017.40
8.0.180.0040.00417.50
8.0.170.0040.00417.29
8.0.160.0000.00717.21
8.0.150.0040.00417.41
8.0.140.0040.00417.36
8.0.130.0000.00613.94
8.0.120.0040.00417.20
8.0.110.0050.00317.29
8.0.100.0000.00717.20
8.0.90.0000.00817.29
8.0.80.0100.00717.27
8.0.70.0050.00217.27
8.0.60.0000.00717.52
8.0.50.0070.00017.18
8.0.30.0110.01117.61
8.0.20.0150.00717.58
8.0.10.0040.00417.49
8.0.00.0100.00717.43
7.4.330.0050.00015.48
7.4.320.0000.00816.99
7.4.300.0000.00716.96
7.4.290.0070.00317.00
7.4.280.0030.00617.12
7.4.270.0000.00716.99
7.4.260.0040.00717.22
7.4.250.0040.00417.05
7.4.240.0020.00617.00
7.4.230.0070.00016.82
7.4.220.0130.01317.11
7.4.210.0000.01617.18
7.4.200.0000.00817.01
7.4.160.0110.00617.04
7.4.150.0370.01717.40
7.4.140.0090.01217.86
7.4.130.0100.00716.99
7.4.120.0080.01017.16
7.4.110.0080.01517.10
7.4.100.0110.00817.07
7.4.90.0060.01216.86
7.4.80.0090.01219.39
7.4.70.0100.01017.07
7.4.60.0070.01017.11
7.4.50.0060.00317.15
7.4.40.0120.00617.17
7.4.30.0080.00817.18
7.4.00.0060.00915.14
7.3.330.0000.00513.94
7.3.320.0040.00413.73
7.3.310.0040.00416.76
7.3.300.0040.00416.84
7.3.290.0030.01317.05
7.3.280.0120.00516.99
7.3.270.0060.01317.40
7.3.260.0130.01017.02
7.3.250.0140.00417.02
7.3.240.0090.00917.07
7.3.230.0100.00716.90
7.3.210.0100.01017.03
7.3.200.0070.01019.39
7.3.190.0110.00716.92
7.3.180.0050.01116.85
7.3.170.0150.00317.31
7.3.160.0070.01016.90
7.3.120.0000.01515.18
7.2.330.0090.00917.46
7.2.320.0090.00917.02
7.2.310.0100.01417.36
7.2.300.0030.01417.10
7.2.290.0080.01117.35
7.2.60.0110.00317.30
7.2.00.0040.01219.82
7.1.200.0100.00316.03
7.1.100.0070.00718.55
7.1.70.0060.00917.28
7.1.60.0070.01119.70
7.1.50.0200.01735.18
7.1.00.0030.07722.66
7.0.200.0030.00616.82
7.0.140.0070.07322.41
7.0.70.0100.07721.95
7.0.60.0130.07321.98
7.0.50.0100.07722.43
7.0.40.0100.08320.47
7.0.30.0070.09020.46
7.0.20.0070.05020.38
7.0.10.0070.03720.37
7.0.00.0130.06320.42
5.6.280.0130.06721.31
5.6.220.0200.05721.10
5.6.210.0100.08320.96
5.6.200.0030.08721.38
5.6.190.0070.09021.37
5.6.180.0100.10021.41
5.6.170.0030.05321.39
5.6.160.0030.09021.43
5.6.150.0070.07721.44
5.6.140.0030.04321.35
5.6.130.0130.05021.32
5.6.120.0030.05021.38
5.6.110.0130.08021.39
5.6.100.0030.08021.32
5.6.90.0070.08321.38
5.6.80.0130.08020.68
5.6.70.0130.07720.65
5.6.60.0000.06020.82
5.6.50.0100.07720.79
5.6.40.0030.05320.78
5.6.30.0070.03720.68
5.6.20.0030.07320.73
5.6.10.0070.07020.69
5.6.00.0030.08720.69
5.5.360.0030.08320.79
5.5.350.0100.08020.73
5.5.340.0030.08021.09
5.5.330.0030.08321.17
5.5.320.0000.08721.16
5.5.310.0030.04721.16
5.5.300.0030.04321.13
5.5.290.0100.07321.05
5.5.280.0100.08321.10
5.5.270.0000.07721.24
5.5.260.0170.08021.08
5.5.250.0030.08721.01
5.5.240.0030.06720.55
5.5.230.0100.07720.44
5.5.220.0130.06720.57
5.5.210.0100.07020.64
5.5.200.0030.08720.61
5.5.190.0000.06020.60
5.5.180.0070.03720.44
5.5.160.0070.08320.62
5.5.150.0070.05720.57
5.5.140.0070.04720.57
5.5.130.0100.07720.53
5.5.120.0100.07320.41
5.5.110.0100.06720.60
5.5.100.0230.06720.43
5.5.90.0100.07720.48
5.5.80.0000.06320.36
5.5.70.0030.07320.30
5.5.60.0030.06020.47
5.5.50.0070.05720.43
5.5.40.0130.08020.49
5.5.30.0070.08320.45
5.5.20.0000.05020.41
5.5.10.0100.07020.29
5.5.00.0100.04720.36
5.4.450.0030.04319.52
5.4.440.0070.08319.63
5.4.430.0100.05719.63
5.4.420.0070.04319.60
5.4.410.0070.07719.65
5.4.400.0100.07719.42
5.4.390.0030.08019.16
5.4.380.0030.07719.40
5.4.370.0030.04319.19
5.4.360.0030.08019.41
5.4.350.0100.03719.30
5.4.340.0000.04719.41
5.4.320.0100.07319.44
5.4.310.0030.07719.41
5.4.300.0000.08719.46
5.4.290.0130.06319.42
5.4.280.0100.07319.36
5.4.270.0070.04719.30
5.4.260.0030.04019.20
5.4.250.0000.07719.35
5.4.240.0130.07019.21
5.4.230.0030.08319.45
5.4.220.0100.06719.18
5.4.210.0000.08319.29
5.4.200.0130.07019.44
5.4.190.0000.08319.19
5.4.180.0030.04319.40
5.4.170.0030.07319.34
5.4.160.0070.04719.44
5.4.150.0030.07019.28
5.4.140.0100.05316.79
5.4.130.0100.07316.76
5.4.120.0070.06316.82
5.4.110.0000.07316.89
5.4.100.0030.07716.84
5.4.90.0070.05316.82
5.4.80.0200.05716.72
5.4.70.0200.06716.74
5.4.60.0100.07016.67
5.4.50.0070.05016.55
5.4.40.0030.05316.84
5.4.30.0000.04716.79
5.4.20.0070.05316.57
5.4.10.0070.07316.59
5.4.00.0070.07716.04
5.3.290.0070.07315.79
5.3.280.0030.06015.79
5.3.270.0100.07015.79
5.3.260.0030.05315.79
5.3.250.0030.08015.79
5.3.240.0070.07015.79
5.3.230.0070.06315.79
5.3.220.0070.07315.79
5.3.210.0000.08315.79
5.3.200.0000.06015.79
5.3.190.0030.05315.79
5.3.180.0070.03715.79
5.3.170.0000.08015.79
5.3.160.0100.07315.79
5.3.150.0130.05715.79
5.3.140.0030.07715.79
5.3.130.0030.08315.79
5.3.120.0030.08315.79
5.3.110.0100.08015.79
5.3.100.0100.07015.79
5.3.90.0130.07015.79
5.3.80.0100.07715.79
5.3.70.0000.08315.79
5.3.60.0000.08315.79
5.3.50.0130.06715.79
5.3.40.0000.05315.79
5.3.30.0070.04015.79
5.3.20.0070.03315.79
5.3.10.0100.03015.79
5.3.00.0030.03715.79
5.2.170.0070.07015.79
5.2.160.0100.02715.79
5.2.150.0100.04715.79
5.2.140.0000.03315.79
5.2.130.0000.03315.79
5.2.120.0000.03015.79
5.2.110.0000.03715.79
5.2.100.0000.03015.79
5.2.90.0000.03315.79
5.2.80.0000.03015.79
5.2.70.0100.02015.79
5.2.60.0030.03015.79
5.2.50.0030.02715.79
5.2.40.0000.04015.79
5.2.30.0070.02715.79
5.2.20.0000.03015.79
5.2.10.0030.02715.79
5.2.00.0030.02715.79
5.1.60.0000.03015.79
5.1.50.0030.04315.79
5.1.40.0030.04015.79
5.1.30.0070.04715.79
5.1.20.0070.04315.79
5.1.10.0000.04715.79
5.1.00.0030.02715.79
5.0.50.0030.03715.79
5.0.40.0000.05015.79
5.0.30.0070.06315.79
5.0.20.0070.02315.79
5.0.10.0030.04315.79
5.0.00.0030.04315.79
4.4.90.0000.01715.79
4.4.80.0000.01715.79
4.4.70.0000.01715.79
4.4.60.0000.01715.79
4.4.50.0030.02715.79
4.4.40.0000.03315.79
4.4.30.0000.01715.79
4.4.20.0070.01315.79
4.4.10.0030.03315.79
4.4.00.0000.04015.79
4.3.110.0070.02015.79
4.3.100.0030.02315.79
4.3.90.0030.01715.79
4.3.80.0100.02315.79
4.3.70.0030.02015.79
4.3.60.0000.01715.79
4.3.50.0000.01715.79
4.3.40.0000.02715.79
4.3.30.0000.01715.79
4.3.20.0030.01315.79
4.3.10.0000.01715.79
4.3.00.0000.03015.79

preferences:
37.42 ms | 400 KiB | 5 Q