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_elements(SimpleXMLElement $element) { list($elementNode) = $element->xpath('.'); $notAttribute = $element->xpath('../*'); return $elementNode != $element and $notAttribute; } $documentElement = $simple; $attributeList = $simple->child->grandchild->attributes(); $attributeListEmpty = $simple->child->attributes(); $attribute = $simple->child->grandchild['a1']; $suite = array( 'is_elements' => array('simplexml_is_elements', array( array(false, $attribute), array(false, $attributeList), array(false, $attributeListEmpty), array(false, $documentElement), array(true, $documentElement->child), array(false, $documentElement->child[0]), array(true, $documentElement->single), array(true, $documentElement->child->grandchild), array(true, $documentElement->child[0]->grandchild), array(false, $documentElement->child[0]->grandchild[0]), )), ); 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.0210.00018.81
8.3.50.0100.00922.37
8.3.40.0070.01119.47
8.3.30.0120.00319.68
8.3.20.0040.00420.62
8.3.10.0040.00422.47
8.3.00.0040.00422.67
8.2.180.0220.00017.13
8.2.170.0120.00322.96
8.2.160.0070.01021.60
8.2.150.0090.00024.18
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0080.00018.25
8.2.110.0150.00322.80
8.2.100.0120.00018.34
8.2.90.0040.00419.75
8.2.80.0030.00618.43
8.2.70.0040.00418.25
8.2.60.0060.00318.54
8.2.50.0050.00318.25
8.2.40.0050.00318.84
8.2.30.0030.00518.67
8.2.20.0030.00618.28
8.2.10.0040.00418.27
8.2.00.0080.00018.40
8.1.280.0040.01125.92
8.1.270.0040.00424.42
8.1.260.0030.01326.35
8.1.250.0080.00028.09
8.1.240.0030.00624.23
8.1.230.0090.00319.66
8.1.220.0080.00018.29
8.1.210.0000.00818.77
8.1.200.0000.01117.73
8.1.190.0030.00618.03
8.1.180.0050.00318.10
8.1.170.0090.00019.14
8.1.160.0030.00722.50
8.1.150.0040.00419.25
8.1.140.0060.00318.00
8.1.130.0040.00418.39
8.1.120.0040.00417.84
8.1.110.0040.00418.04
8.1.100.0050.00317.88
8.1.90.0080.00317.94
8.1.80.0040.00418.06
8.1.70.0040.00417.91
8.1.60.0040.00418.06
8.1.50.0050.00517.93
8.1.40.0000.00818.09
8.1.30.0060.00318.21
8.1.20.0030.00518.22
8.1.10.0000.00817.93
8.1.00.0060.00317.91
8.0.300.0040.00418.77
8.0.290.0000.00817.68
8.0.280.0000.00818.94
8.0.270.0000.00717.74
8.0.260.0040.00417.48
8.0.250.0030.00317.43
8.0.240.0000.00717.60
8.0.230.0070.00017.37
8.0.220.0040.00417.34
8.0.210.0000.00817.56
8.0.200.0000.00617.41
8.0.190.0040.00417.57
8.0.180.0040.00417.37
8.0.170.0080.00017.57
8.0.160.0000.00817.47
8.0.150.0070.00017.25
8.0.140.0000.00817.30
8.0.130.0070.00014.00
8.0.120.0000.00817.40
8.0.110.0000.00917.25
8.0.100.0000.00817.39
8.0.90.0040.00417.39
8.0.80.0160.00617.49
8.0.70.0030.00617.30
8.0.60.0040.00417.37
8.0.50.0000.00817.23
8.0.30.0170.00717.72
8.0.20.0120.01317.71
8.0.10.0040.00417.59
8.0.00.0050.01317.31
7.4.330.0000.00515.58
7.4.320.0070.00017.20
7.4.300.0030.00317.03
7.4.290.0030.00317.19
7.4.280.0030.00517.03
7.4.270.0030.00617.04
7.4.260.0000.00716.96
7.4.250.0030.00516.91
7.4.240.0050.00317.05
7.4.230.0070.00016.87
7.4.220.0060.01217.11
7.4.210.0110.00817.06
7.4.200.0050.00316.83
7.4.190.0000.00817.14
7.4.160.0120.00416.81
7.4.150.0070.01117.40
7.4.140.0120.00917.86
7.4.130.0140.00817.01
7.4.120.0120.00617.05
7.4.110.0120.00617.20
7.4.100.0120.00816.93
7.4.90.0040.01817.06
7.4.80.0160.00616.89
7.4.70.0030.01516.98
7.4.60.0030.01317.10
7.4.50.0060.00017.01
7.4.40.0080.00822.77
7.4.30.0080.00817.04
7.4.00.0100.00615.30
7.3.330.0000.00513.86
7.3.320.0030.00313.86
7.3.310.0040.00416.93
7.3.300.0050.00216.85
7.3.290.0150.00616.94
7.3.280.0080.00916.90
7.3.270.0100.01317.40
7.3.260.0090.01216.88
7.3.250.0150.00317.05
7.3.240.0070.01017.11
7.3.230.0090.01016.86
7.3.210.0100.00716.82
7.3.200.0130.01019.39
7.3.190.0140.00317.15
7.3.180.0070.01017.08
7.3.170.0110.00716.91
7.3.160.0040.01316.88
7.3.120.0030.01315.33
7.2.330.0130.00617.38
7.2.320.0080.01417.25
7.2.310.0160.00417.32
7.2.300.0120.00617.27
7.2.290.0100.00717.09
7.2.60.0040.00817.17
7.2.00.0000.01219.97
7.1.200.0030.01015.97
7.1.100.0030.01018.38
7.1.70.0040.00417.57
7.1.60.0100.01619.82
7.1.50.0090.01317.32
7.1.00.0030.07722.69
7.0.200.0130.00516.90
7.0.140.0000.08022.41
7.0.70.0070.03722.13
7.0.60.0000.04322.02
7.0.50.0030.04322.31
7.0.40.0070.04020.47
7.0.30.0100.05020.31
7.0.20.0030.05020.34
7.0.10.0000.03720.37
7.0.00.0000.03720.37
5.6.280.0030.07721.46
5.6.220.0070.03720.93
5.6.210.0030.04020.84
5.6.200.0100.02721.47
5.6.190.0030.06321.47
5.6.180.0070.03721.33
5.6.170.0030.03721.44
5.6.160.0000.06021.36
5.6.150.0030.05021.45
5.6.140.0000.06021.33
5.6.130.0000.04721.33
5.6.120.0000.04721.32
5.6.110.0000.04321.20
5.6.100.0030.04321.24
5.6.90.0030.08021.30
5.6.80.0030.04720.71
5.6.70.0000.04320.71
5.6.60.0000.04020.71
5.6.50.0000.06720.77
5.6.40.0000.04020.72
5.6.30.0030.03720.83
5.6.20.0000.04020.68
5.6.10.0000.03320.84
5.6.00.0000.03720.68
5.5.360.0030.03320.76
5.5.350.0070.03720.79
5.5.340.0070.07321.21
5.5.330.0030.04021.18
5.5.320.0030.04321.12
5.5.310.0030.03321.21
5.5.300.0000.04721.25
5.5.290.0030.04021.20
5.5.280.0030.04021.23
5.5.270.0000.05721.25
5.5.260.0030.04021.11
5.5.250.0030.04020.91
5.5.240.0030.04020.54
5.5.230.0070.03720.52
5.5.220.0030.03720.49
5.5.210.0000.04020.44
5.5.200.0070.03320.36
5.5.190.0030.03020.43
5.5.180.0000.04020.40
5.5.160.0000.04720.57
5.5.150.0070.03320.47
5.5.140.0000.04020.36
5.5.130.0070.08320.49
5.5.120.0070.07020.49
5.5.110.0000.08720.56
5.5.100.0030.08320.33
5.5.90.0130.07720.44
5.5.80.0100.04320.46
5.5.70.0030.04320.37
5.5.60.0000.04320.29
5.5.50.0070.07720.28
5.5.40.0070.07320.34
5.5.30.0030.08020.43
5.5.20.0070.07320.36
5.5.10.0030.07720.34
5.5.00.0070.06020.34
5.4.450.0000.04019.74
5.4.440.0030.04019.78
5.4.430.0000.04019.73
5.4.420.0000.04019.61
5.4.410.0030.06719.61
5.4.400.0000.04019.28
5.4.390.0000.04319.40
5.4.380.0070.03319.43
5.4.370.0030.07019.27
5.4.360.0030.03719.29
5.4.350.0030.03719.39
5.4.340.0130.02319.42
5.4.320.0030.05319.27
5.4.310.0030.04019.29
5.4.300.0070.05719.26
5.4.290.0100.07019.45
5.4.280.0100.03719.41
5.4.270.0100.07319.27
5.4.260.0030.05319.39
5.4.250.0030.03719.18
5.4.240.0000.04719.14
5.4.230.0100.07319.18
5.4.220.0030.07319.28
5.4.210.0070.07319.39
5.4.200.0070.07719.40
5.4.190.0070.08019.53
5.4.180.0000.08019.38
5.4.170.0100.07019.49
5.4.160.0070.07719.26
5.4.150.0030.06319.16
5.4.140.0030.08016.79
5.4.130.0030.07716.75
5.4.120.0030.05716.79
5.4.110.0070.07016.73
5.4.100.0030.05716.75
5.4.90.0070.06716.66
5.4.80.0030.07716.79
5.4.70.0000.05016.83
5.4.60.0030.07016.83
5.4.50.0000.05716.58
5.4.40.0030.05716.70
5.4.30.0030.07316.45
5.4.20.0030.07316.48
5.4.10.0030.07016.68
5.4.00.0000.08016.09
5.3.290.0000.07315.11
5.3.280.0030.07714.91
5.3.270.0100.07714.98
5.3.260.0100.07314.95
5.3.250.0000.05314.99
5.3.240.0130.06314.89
5.3.230.0000.08315.08
5.3.220.0000.07715.00
5.3.210.0030.06315.03
5.3.200.0030.07314.85
5.3.190.0070.06314.85
5.3.180.0030.03715.03
5.3.170.0070.05714.84
5.3.160.0030.04714.88
5.3.150.0030.03714.92
5.3.140.0070.07314.96
5.3.130.0070.06314.83
5.3.120.0070.04714.98
5.3.110.0000.04314.87
5.3.100.0100.06714.42
5.3.90.0070.07314.32
5.3.80.0070.03314.39
5.3.70.0030.07014.37
5.3.60.0070.04714.46
5.3.50.0030.03314.33
5.3.40.0000.07314.38
5.3.30.0000.07714.33
5.3.20.0030.07014.03
5.3.10.0030.06314.12
5.3.00.0000.06313.99
5.2.170.0030.05011.56
5.2.160.0000.06311.57
5.2.150.0030.06311.49
5.2.140.0030.05311.55
5.2.130.0030.06711.48
5.2.120.0100.05711.56
5.2.110.0070.06011.48
5.2.100.0030.06011.48
5.2.90.0000.05711.48
5.2.80.0030.06011.48
5.2.70.0000.05711.48
5.2.60.0130.04311.52
5.2.50.0030.06011.48
5.2.40.0030.06011.48
5.2.30.0030.06011.48
5.2.20.0070.05711.48
5.2.10.0070.06011.48
5.2.00.0070.06011.48
5.1.60.0030.03711.48
5.1.50.0030.05711.48
5.1.40.0030.05311.48
5.1.30.0030.05711.48
5.1.20.0070.05711.48
5.1.10.0030.04711.48
5.1.00.0000.05711.48
5.0.50.0030.04711.48
5.0.40.0000.05011.48
5.0.30.0070.05711.48
5.0.20.0000.04711.48
5.0.10.0000.03711.48
5.0.00.0000.07011.48
4.4.90.0030.03311.48
4.4.80.0070.03011.48
4.4.70.0000.03711.48
4.4.60.0100.02011.48
4.4.50.0030.03011.48
4.4.40.0000.05011.48
4.4.30.0000.03711.48
4.4.20.0000.03711.48
4.4.10.0000.04011.48
4.4.00.0100.05011.48
4.3.110.0000.03011.48
4.3.100.0000.03711.48
4.3.90.0070.03011.48
4.3.80.0000.05711.48
4.3.70.0000.03711.48
4.3.60.0070.03011.48
4.3.50.0030.02311.48
4.3.40.0000.04711.48
4.3.30.0030.03311.48
4.3.20.0030.03011.48
4.3.10.0070.03011.48
4.3.00.0070.02311.48

preferences:
41.91 ms | 401 KiB | 5 Q