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> '; $xml = strtr($xml, array("\r" => "")); // fix for 3v4l.org using CRLF input instead of LF file-format on disk @ home $simple = new SimpleXMLElement($xml); /** * @param SimpleXMLElement $element * @return string */ function simplexml_get_xml_without_declaration(SimpleXMLElement $element) { list($elementNode) = $element->xpath('.'); list($documentElement) = $element->xpath('/*'); $xml = $element->asXML(); if ($elementNode == $element and $documentElement == $element) { list(, $xml) = explode("\n", $xml, 2); } return $xml; } $documentElement = $simple; $attributeList = $simple->child->grandchild->attributes(); $attributeListEmpty = $simple->child->attributes(); $attribute = $simple->child->grandchild['a1']; $suite = array( 'get_xml_nodecl' => array('simplexml_get_xml_without_declaration', array( array($xml, $simple), array($simple->child->asXML(), $simple->child), )), ); 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.01016.88
8.3.50.0090.01017.01
8.3.40.0100.00619.34
8.3.30.0070.00719.21
8.3.20.0110.00419.14
8.3.10.0000.00919.28
8.3.00.0000.01619.83
8.2.180.0000.01516.88
8.2.170.0180.00422.96
8.2.160.0060.01019.59
8.2.150.0030.00624.18
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0090.00321.09
8.2.110.0040.00420.82
8.2.100.0030.00920.45
8.2.90.0000.00818.13
8.2.80.0050.00319.39
8.2.70.0030.00518.13
8.2.60.0000.00818.41
8.2.50.0050.00318.07
8.2.40.0060.00320.45
8.2.30.0050.00318.28
8.2.20.0030.00718.08
8.2.10.0030.00518.38
8.2.00.0080.00318.19
8.1.280.0090.00625.92
8.1.270.0040.00423.99
8.1.260.0070.00726.35
8.1.250.0060.00328.09
8.1.240.0100.00019.52
8.1.230.0060.00618.16
8.1.220.0000.00818.41
8.1.210.0060.00318.77
8.1.200.0070.00317.85
8.1.190.0030.00617.85
8.1.180.0000.00818.10
8.1.170.0050.00319.45
8.1.160.0000.00719.42
8.1.150.0060.00319.15
8.1.140.0040.00417.79
8.1.130.0070.00017.95
8.1.120.0050.00317.86
8.1.110.0080.00317.92
8.1.100.0070.00317.98
8.1.90.0000.00717.85
8.1.80.0000.00817.98
8.1.70.0030.00317.95
8.1.60.0040.00418.01
8.1.50.0030.00617.95
8.1.40.0050.00317.84
8.1.30.0000.00818.01
8.1.20.0090.00017.89
8.1.10.0060.00317.93
8.1.00.0030.00618.04
8.0.300.0080.00018.77
8.0.290.0050.00317.25
8.0.280.0000.00718.98
8.0.270.0070.00017.64
8.0.260.0000.00717.25
8.0.250.0080.00017.45
8.0.240.0100.00017.37
8.0.230.0000.00717.50
8.0.220.0000.00817.35
8.0.210.0030.00317.32
8.0.200.0060.00317.28
8.0.190.0060.00317.25
8.0.180.0030.00717.29
8.0.170.0040.00717.39
8.0.160.0060.00317.35
8.0.150.0000.00917.38
8.0.140.0090.00317.17
8.0.130.0030.00313.76
8.0.120.0100.00017.30
8.0.110.0080.00017.38
8.0.100.0000.00717.23
8.0.90.0050.00317.36
8.0.80.0100.01017.44
8.0.70.0000.00817.33
8.0.60.0040.00417.52
8.0.50.0040.00417.43
8.0.30.0120.00917.77
8.0.20.0100.01017.57
8.0.10.0040.00417.41
8.0.00.0120.00817.24
7.4.330.0000.00613.43
7.4.320.0050.00317.02
7.4.300.0060.00016.97
7.4.290.0000.00717.16
7.4.280.0050.00317.02
7.4.270.0070.00016.76
7.4.260.0000.00613.79
7.4.250.0030.00517.00
7.4.240.0030.00316.94
7.4.230.0040.00416.84
7.4.220.0130.00616.91
7.4.210.0130.00317.01
7.4.200.0000.00917.02
7.4.190.0040.00417.09
7.4.160.0150.00616.84
7.4.150.0120.00616.91
7.4.140.0150.00316.94
7.4.130.0040.01317.07
7.4.120.0140.00416.89
7.4.110.0130.00616.88
7.4.100.0120.00716.80
7.4.90.0110.00817.05
7.4.80.0090.00919.39
7.4.70.0060.01217.01
7.4.60.0070.01416.98
7.4.50.0000.00616.78
7.4.40.0000.01316.84
7.4.30.0120.00416.84
7.4.00.0080.01015.12
7.3.330.0000.00713.65
7.3.320.0090.00013.78
7.3.310.0030.00516.60
7.3.300.0040.00416.79
7.3.290.0060.01016.83
7.3.280.0080.00816.87
7.3.270.0090.00916.96
7.3.260.0000.01717.23
7.3.250.0170.00816.93
7.3.240.0140.01116.96
7.3.230.0140.00716.86
7.3.210.0090.00917.14
7.3.200.0150.00316.99
7.3.190.0090.00916.87
7.3.180.0100.01316.93
7.3.170.0030.01216.82
7.3.160.0130.00317.14
7.3.120.0090.01115.06
7.3.110.0070.00915.09
7.3.100.0050.01015.19
7.3.90.0100.00715.06
7.3.80.0050.01014.89
7.3.70.0070.00515.06
7.3.60.0100.00715.15
7.3.50.0090.00414.87
7.3.40.0040.01014.95
7.3.30.0090.00114.98
7.3.20.0070.00616.77
7.3.10.0030.01216.90
7.3.00.0050.00716.84
7.2.330.0070.01117.36
7.2.320.0140.00316.94
7.2.310.0130.00617.30
7.2.300.0230.00017.25
7.2.290.0070.01017.32
7.2.250.0070.01015.26
7.2.240.0050.01615.31
7.2.230.0080.00915.34
7.2.220.0050.00815.26
7.2.210.0100.00515.34
7.2.200.0050.01015.38
7.2.190.0070.00615.34
7.2.180.0040.01015.31
7.2.170.0060.00915.17
7.2.160.0060.00615.41
7.2.150.0110.00417.08
7.2.140.0030.01417.04
7.2.130.0060.00617.11
7.2.120.0100.00617.16
7.2.110.0060.01017.19
7.2.100.0070.00717.03
7.2.90.0000.01217.20
7.2.80.0030.01317.08
7.2.70.0040.00717.01
7.2.60.0070.00917.09
7.2.50.0080.00417.21
7.2.40.0060.00917.11
7.2.30.0090.00617.30
7.2.20.0070.01017.00
7.2.10.0030.01417.07
7.2.00.0070.01018.44
7.1.330.0080.00616.10
7.1.320.0020.01216.01
7.1.310.0100.00616.09
7.1.300.0110.00715.92
7.1.290.0030.01215.91
7.1.280.0020.00916.13
7.1.270.0050.00816.16
7.1.260.0080.00715.94
7.1.250.0060.01015.84
7.1.200.0040.01116.01
7.1.100.0040.00818.54
7.1.70.0030.01017.41
7.1.60.0140.00719.30
7.1.50.0070.01716.95
7.1.00.0070.03722.63
7.0.200.0000.00717.09
7.0.140.0100.07022.23
7.0.110.0070.06720.25
7.0.100.0330.07720.39
7.0.90.0070.05720.21
7.0.80.0500.05720.30
7.0.70.0030.04320.15
7.0.60.0070.03720.14
7.0.50.0430.07020.37
7.0.40.0000.07719.86
7.0.30.0030.08019.94
7.0.20.0100.08019.89
7.0.10.0030.03719.98
7.0.00.0070.07019.95
5.6.280.0030.07321.18
5.6.260.0130.03720.91
5.6.250.0030.05020.91
5.6.240.0070.06020.80
5.6.230.0030.03720.77
5.6.220.0070.03720.82
5.6.210.0100.08720.81
5.6.200.0070.04720.88
5.6.190.0000.05020.82
5.6.180.0030.04020.79
5.6.170.0170.04320.86
5.6.160.0100.07020.83
5.6.150.0030.07720.77
5.6.140.0100.07020.98
5.6.130.0030.08320.91
5.6.120.0070.05320.85
5.6.110.0030.05020.75
5.6.100.0100.07720.91
5.6.90.0100.05320.77
5.6.80.0030.04020.13
5.6.70.0100.03720.20
5.6.60.0070.03720.36
5.6.50.0100.03020.25
5.6.40.0030.03320.24
5.6.30.0000.04320.20
5.6.20.0070.04320.21
5.6.10.0100.04020.22
5.6.00.0100.03320.14
5.5.380.0030.08317.68
5.5.370.0070.03317.71
5.5.360.0030.05317.79
5.5.350.0030.05318.01
5.5.340.0000.05318.31
5.5.330.0070.08018.11
5.5.320.0030.08318.15
5.5.310.0000.04318.27
5.5.300.0070.05318.48
5.5.290.0070.04718.09
5.5.280.0000.04718.38
5.5.270.0070.05718.36
5.5.260.0030.04018.21
5.5.250.0000.04317.81
5.5.240.0100.03317.74
5.5.230.0070.04317.82
5.5.220.0070.04317.67
5.5.210.0100.04317.83
5.5.200.0070.03717.45
5.5.190.0130.03017.49
5.5.180.0130.06317.49
5.5.160.0130.06017.90
5.5.150.0000.04018.01
5.5.140.0070.07017.61
5.5.130.0000.08317.91
5.5.120.0200.06317.45
5.5.110.0170.06717.80
5.5.100.0030.03317.81
5.5.90.0000.07017.70
5.5.80.0030.04317.80
5.5.70.0070.03717.66
5.5.60.0030.03317.36
5.5.50.0000.04017.57
5.5.40.0100.04317.55
5.5.30.0070.03017.70
5.5.20.0070.03717.24
5.5.10.0070.04317.79
5.5.00.0070.04317.45
5.4.450.0030.05719.91
5.4.440.0030.08319.65
5.4.430.0030.04319.80
5.4.420.0030.04719.85
5.4.410.0000.05319.49
5.4.400.0000.04319.34
5.4.390.0070.03319.11
5.4.380.0000.04019.18
5.4.370.0030.04719.44
5.4.360.0100.04319.37
5.4.350.0070.02719.35
5.4.340.0100.06719.45
5.4.320.0070.03019.46
5.4.310.0030.04319.32
5.4.300.0100.07719.33
5.4.290.0100.06319.32
5.4.280.0000.04719.52
5.4.270.0070.05719.14
5.4.260.0030.03319.48
5.4.250.0130.06319.44
5.4.240.0030.04019.30
5.4.230.0000.04319.48
5.4.220.0070.03019.33
5.4.210.0000.04319.52
5.4.200.0100.03019.52
5.4.190.0070.05719.36
5.4.180.0100.02719.05
5.4.170.0000.03719.49
5.4.160.0000.04019.28
5.4.150.0030.04019.35
5.4.140.0030.03316.71
5.4.130.0070.02716.79
5.4.120.0070.03316.78
5.4.110.0030.04016.60
5.4.100.0000.04716.88
5.4.90.0000.04716.84
5.4.80.0070.03316.84
5.4.70.0070.03016.86
5.4.60.0030.03716.61
5.4.50.0070.05716.76
5.4.40.0030.07716.70
5.4.30.0070.05016.64
5.4.20.0070.05316.73
5.4.10.0030.05316.50
5.4.00.0100.04716.31
5.3.290.0130.06315.01
5.3.280.0000.04014.88
5.3.270.0070.04314.90
5.3.260.0000.03714.81
5.3.250.0000.04014.96
5.3.240.0030.03314.85
5.3.230.0030.03314.84
5.3.220.0070.02714.85
5.3.210.0000.03314.91
5.3.200.0030.03714.90
5.3.190.0070.07714.78
5.3.180.0130.06014.79
5.3.170.0070.03714.91
5.3.160.0000.06314.84
5.3.150.0070.04314.85
5.3.140.0070.05314.87
5.3.130.0030.08014.75
5.3.120.0000.06314.84
5.3.110.0070.03014.91
5.3.100.0100.05714.25
5.3.90.0100.03014.25
5.3.80.0000.05014.37
5.3.70.0070.05014.29
5.3.60.0100.04714.19
5.3.50.0000.07314.29
5.3.40.0030.07314.28
5.3.30.0100.04714.18
5.3.20.0070.03313.90
5.3.10.0000.04014.09
5.3.00.0100.05013.84
5.2.170.0030.03011.96
5.2.160.0170.05311.96
5.2.150.0030.06311.96
5.2.140.0070.04711.96
5.2.130.0070.04711.96
5.2.120.0000.04711.96
5.2.110.0030.03711.96
5.2.100.0070.03011.96
5.2.90.0000.04311.96
5.2.80.0030.03711.96
5.2.70.0070.02711.96
5.2.60.0130.06011.96
5.2.50.0030.03011.96
5.2.40.0100.04311.96
5.2.30.0030.02711.96
5.2.20.0000.04711.96
5.2.10.0030.02311.96
5.2.00.0030.02711.96
5.1.60.0030.04311.96
5.1.50.0100.04711.96
5.1.40.0070.05011.96
5.1.30.0070.03011.96
5.1.20.0000.03711.96
5.1.10.0070.04311.96
5.1.00.0070.03711.96
5.0.50.0070.03711.96
5.0.40.0030.02311.96
5.0.30.0030.06311.96
5.0.20.0000.02011.96
5.0.10.0030.02711.96
5.0.00.0030.06311.96
4.4.90.0000.03711.96
4.4.80.0070.01711.96
4.4.70.0030.02311.96
4.4.60.0000.01311.96
4.4.50.0000.01311.96
4.4.40.0000.05311.96
4.4.30.0030.01711.96
4.4.20.0030.01311.96
4.4.10.0000.02011.96
4.4.00.0000.05711.96
4.3.110.0000.02011.96
4.3.100.0000.02711.96
4.3.90.0000.02011.96
4.3.80.0000.04011.96
4.3.70.0070.01311.96
4.3.60.0030.01311.96
4.3.50.0000.03011.96
4.3.40.0030.02311.96
4.3.30.0070.01011.96
4.3.20.0000.01711.96
4.3.10.0030.01311.96
4.3.00.0000.03311.96

preferences:
47.26 ms | 401 KiB | 5 Q