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> '; echo substr_count($xml, "\r"); return; $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.70.0110.01116.38
8.3.60.0140.00718.18
8.3.50.0190.00621.20
8.3.40.0150.00018.75
8.3.30.0030.01020.33
8.3.20.0000.01820.34
8.3.10.0070.01122.00
8.3.00.0040.00422.52
8.2.180.0110.00418.16
8.2.170.0160.00622.96
8.2.160.0110.00420.38
8.2.150.0160.00324.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0000.00819.63
8.2.110.0090.00022.26
8.2.100.0070.00419.39
8.2.90.0030.00519.27
8.2.80.0080.00019.23
8.2.70.0000.00817.50
8.2.60.0040.00418.04
8.2.50.0050.00318.07
8.2.40.0050.00318.22
8.2.30.0080.00018.11
8.2.20.0040.00417.73
8.2.10.0080.00017.53
8.2.00.0040.00417.72
8.1.280.0120.00325.92
8.1.270.0000.00820.35
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0040.00423.97
8.1.230.0080.00419.16
8.1.220.0060.00317.74
8.1.210.0040.00418.77
8.1.200.0030.00617.23
8.1.190.0040.00417.40
8.1.180.0000.00820.29
8.1.170.0000.00818.42
8.1.160.0070.00322.30
8.1.150.0050.00318.61
8.1.140.0000.00717.48
8.1.130.0030.00317.77
8.1.120.0000.00817.48
8.1.110.0000.00817.36
8.1.100.0000.00717.45
8.1.90.0080.00017.33
8.1.80.0040.00417.44
8.1.70.0070.00017.33
8.1.60.0060.00317.61
8.1.50.0050.00317.39
8.1.40.0040.00417.48
8.1.30.0080.00017.50
8.1.20.0050.00417.61
8.1.10.0030.00517.56
8.1.00.0000.00817.39
8.0.300.0070.00018.77
8.0.290.0040.00417.05
8.0.280.0070.00018.36
8.0.270.0000.00717.18
8.0.260.0000.00816.77
8.0.250.0030.00316.94
8.0.240.0060.00316.97
8.0.230.0000.00816.95
8.0.220.0030.00316.75
8.0.210.0000.00716.77
8.0.200.0050.00216.84
8.0.190.0000.00716.85
8.0.180.0040.00716.94
8.0.170.0040.00416.96
8.0.160.0040.00416.74
8.0.150.0020.00516.76
8.0.140.0030.00716.86
8.0.130.0000.00613.25
8.0.120.0040.00416.89
8.0.110.0040.00416.89
8.0.100.0000.00816.91
8.0.90.0070.00016.70
8.0.80.0040.01216.90
8.0.70.0040.00416.71
8.0.60.0040.00416.76
8.0.50.0040.00416.99
8.0.30.0110.00817.17
8.0.20.0110.00817.40
8.0.10.0030.00516.86
8.0.00.0100.01216.96
7.4.330.0050.00015.00
7.4.320.0040.00416.57
7.4.300.0000.00616.55
7.4.290.0060.00316.39
7.4.280.0000.00816.49
7.4.270.0040.00316.64
7.4.260.0030.00716.56
7.4.250.0000.00716.40
7.4.240.0070.00016.51
7.4.230.0070.00016.68
7.4.220.0100.01716.60
7.4.210.0080.00716.43
7.4.200.0050.00216.29
7.4.190.0080.00016.44
7.4.160.0040.01116.50
7.4.150.0070.01017.40
7.4.140.0080.01317.86
7.4.130.0110.00616.48
7.4.120.0050.01416.44
7.4.110.0160.00316.57
7.4.100.0070.01116.50
7.4.90.0090.00916.52
7.4.80.0090.00919.39
7.4.70.0150.00716.45
7.4.60.0100.00616.40
7.4.50.0000.00816.36
7.4.40.0060.00922.77
7.4.30.0100.00716.59
7.4.00.0030.01014.95
7.3.330.0030.00313.25
7.3.320.0050.00013.16
7.3.310.0000.00716.08
7.3.300.0000.00816.07
7.3.290.0070.00816.21
7.3.280.0050.01216.21
7.3.270.0120.00617.40
7.3.260.0150.00316.35
7.3.250.0100.01116.25
7.3.240.0100.01016.24
7.3.230.0070.01016.53
7.3.210.0090.00916.07
7.3.200.0090.01519.39
7.3.190.0140.00916.54
7.3.180.0130.00316.39
7.3.170.0080.00816.29
7.3.160.0150.00016.18
7.3.120.0030.01014.64
7.2.330.0090.00816.57
7.2.320.0030.01816.43
7.2.310.0080.00916.29
7.2.300.0130.00316.61
7.2.290.0100.01616.67
7.2.00.0000.01519.34
7.1.100.0170.00017.85
7.1.70.0050.00216.89
7.1.60.0040.02119.50
7.1.50.0060.01316.54
7.1.00.0030.05022.43
7.0.200.0040.00416.80
7.0.140.0100.06321.93
7.0.100.0170.06320.02
7.0.90.0130.04320.06
7.0.80.0030.07719.93
7.0.70.0030.08320.00
7.0.60.0100.04320.13
7.0.50.0270.08320.38
7.0.40.0270.06020.09
7.0.30.0030.05320.11
7.0.20.0030.04320.04
7.0.10.0100.05019.99
7.0.00.0100.08020.03
5.6.280.0000.07720.88
5.6.250.0000.08720.66
5.6.240.0170.06020.63
5.6.230.0030.07320.70
5.6.220.0070.08320.65
5.6.210.0100.08020.50
5.6.200.0030.04321.07
5.6.190.0030.04721.14
5.6.180.0170.05321.06
5.6.170.0070.08020.98
5.6.160.0070.05021.05
5.6.150.0130.03720.98
5.6.140.0070.06021.07
5.6.130.0000.04721.11
5.6.120.0130.08021.11
5.6.110.0030.05020.99
5.6.100.0030.08721.12
5.6.90.0130.06321.15
5.6.80.0100.07320.45
5.6.70.0070.05720.46
5.6.60.0100.06720.54
5.6.50.0230.06320.44
5.6.40.0100.07020.45
5.6.30.0070.08020.43
5.6.20.0100.03720.55
5.6.10.0070.07020.36
5.6.00.0070.05020.41
5.5.380.0230.07720.46
5.5.370.0030.08320.48
5.5.360.0070.06720.53
5.5.350.0170.04020.50
5.5.340.0130.04020.81
5.5.330.0100.07720.91
5.5.320.0100.04720.89
5.5.310.0100.06020.92
5.5.300.0130.07320.93
5.5.290.0070.04020.88
5.5.280.0000.08320.89
5.5.270.0030.08320.92
5.5.260.0030.08020.93
5.5.250.0030.08020.75
5.5.240.0070.07020.28
5.5.230.0100.07020.31
5.5.220.0030.06020.18
5.5.210.0100.07020.21
5.5.200.0070.03320.02
5.5.190.0130.07320.20
5.5.180.0100.03320.02
5.5.160.0030.05720.14
5.5.150.0000.07320.30
5.5.140.0000.05020.29
5.5.130.0000.05020.01
5.5.120.0130.04320.13
5.5.110.0070.08320.23
5.5.100.0030.08320.18
5.5.90.0070.04720.20
5.5.80.0070.07320.19
5.5.70.0030.04020.13
5.5.60.0030.07319.93
5.5.50.0130.07020.08
5.5.40.0100.07320.15
5.5.30.0030.06020.08
5.5.20.0100.07319.98
5.5.10.0130.05720.11
5.5.00.0070.06020.05
5.4.450.0030.09019.43
5.4.440.0030.06319.28
5.4.430.0170.07019.53
5.4.420.0070.07719.32
5.4.410.0100.08019.23
5.4.400.0130.06319.05
5.4.390.0030.04319.18
5.4.380.0130.06319.04
5.4.370.0100.07719.09
5.4.360.0070.07719.17
5.4.350.0000.04019.04
5.4.340.0070.07319.04
5.4.320.0030.06019.05
5.4.310.0100.03718.91
5.4.300.0130.07318.87
5.4.290.0100.06718.95
5.4.280.0070.07719.13
5.4.270.0100.06019.12
5.4.260.0000.04719.03
5.4.250.0100.07319.04
5.4.240.0070.08019.04
5.4.230.0070.07319.18
5.4.220.0100.05719.13
5.4.210.0000.04018.96
5.4.200.0070.07318.84
5.4.190.0070.06718.89
5.4.180.0000.04718.94
5.4.170.0170.06319.13
5.4.160.0000.04319.17
5.4.150.0200.07019.11
5.4.140.0030.05716.39
5.4.130.0070.06316.51
5.4.120.0030.04716.48
5.4.110.0030.07716.55
5.4.100.0070.03316.57
5.4.90.0070.06316.39
5.4.80.0000.03716.53
5.4.70.0070.07016.36
5.4.60.0100.06716.49
5.4.50.0070.06716.36
5.4.40.0030.07316.37
5.4.30.0100.05016.48
5.4.20.0000.07316.41
5.4.10.0030.03316.34
5.4.00.0070.06315.78
5.3.290.0070.07714.64
5.3.280.0030.03714.62
5.3.270.0200.03014.67
5.3.260.0130.06714.59
5.3.250.0070.04314.64
5.3.240.0030.04314.70
5.3.230.0100.04714.69
5.3.220.0130.05714.60
5.3.210.0030.07014.59
5.3.200.0130.06014.57
5.3.190.0030.03314.63
5.3.180.0000.06714.71
5.3.170.0030.08014.57
5.3.160.0070.06714.61
5.3.150.0000.03714.65
5.3.140.0030.03714.64
5.3.130.0100.06014.64
5.3.120.0070.06014.54
5.3.110.0030.06014.64
5.3.100.0070.06714.09
5.3.90.0130.02714.11
5.3.80.0100.06314.06
5.3.70.0030.07314.05
5.3.60.0100.07014.14
5.3.50.0100.06713.91
5.3.40.0030.07014.03
5.3.30.0030.07314.05
5.3.20.0000.06013.73
5.3.10.0070.07013.70
5.3.00.0000.07713.70
5.2.170.0030.06311.31
5.2.160.0030.06311.24
5.2.150.0070.06311.09
5.2.140.0030.06311.32
5.2.130.0100.02311.25
5.2.120.0000.03011.00
5.2.110.0000.06011.14
5.2.100.0130.05711.16
5.2.90.0000.04011.17
5.2.80.0030.02711.11
5.2.70.0070.03711.19
5.2.60.0030.03711.00
5.2.50.0000.03311.19
5.2.40.0000.04011.16
5.2.30.0000.03011.07
5.2.20.0000.03711.13
5.2.10.0000.03010.81
5.2.00.0000.03710.71
5.1.60.0000.02310.61
5.1.50.0070.02010.61
5.1.40.0070.02010.61
5.1.30.0030.02710.61
5.1.20.0030.02710.61
5.1.10.0000.02710.61
5.1.00.0000.02710.61
5.0.50.0030.02010.61
5.0.40.0000.02010.61
5.0.30.0000.03310.61
5.0.20.0000.02710.61
5.0.10.0030.01710.61
5.0.00.0000.06310.61
4.4.90.0000.01710.61
4.4.80.0000.01310.61
4.4.70.0000.01710.61
4.4.60.0030.01310.61
4.4.50.0000.01710.61
4.4.40.0030.02310.61
4.4.30.0000.02010.61
4.4.20.0070.01010.61
4.4.10.0000.01710.61
4.4.00.0000.03310.61
4.3.110.0000.01310.61
4.3.100.0030.02310.61
4.3.90.0100.02310.61
4.3.80.0030.04010.61
4.3.70.0070.03010.61
4.3.60.0000.03710.61
4.3.50.0000.03710.61
4.3.40.0000.04310.61
4.3.30.0000.03310.61
4.3.20.0000.02010.61
4.3.10.0100.00710.61
4.3.00.0000.01310.61

preferences:
36.91 ms | 401 KiB | 5 Q