3v4l.org

run code in 300+ PHP versions simultaneously
<?php function applyHLToSiblings(DOMDocument $D){ $words[0] = "cart"; /* $words[1] = "car"; $words[2] = "cartel"; $words[3] = "art"; $words[4] = "drug"; $words[5] = "drugs"; $words[6] = "rug"; $words[7] = "rugs"; */ $mt = function($content) use($D){ return $D->createTextNode($content); }; $ms = function($content = null, $name) use($D){ $span = $D->createElement("span"); $span->setAttribute("class", "word$name"); $content === null ?: $span->appendChild($content); return $span; }; $ps = function($siblingsContainer, $searchString, $name) use($D, $ms, $mt){ foreach($siblingsContainer->childNodes as $node){ if($node instanceof DOMText){ if(mb_strlen($node->textContent, "UTF-8") >= mb_strlen($searchString)){ $o = mb_strpos($node->textContent, $searchString); if($o !== false){ $l = mb_strlen($searchString, "UTF-8"); $before = mb_substr($node->textContent, 0, $o); $wrap = mb_substr($node->textContent, $o, $l); $after = mb_substr($node->textContent, $o + $l); $after ? $node->parentNode->insertBefore($mt($after) , $node->nextSibling) : null; $node->parentNode->insertBefore($ms($mt($wrap), $name) , $node->nextSibling); $before ? $node->parentNode->insertBefore($mt($before) , $node->nextSibling) : null; $node->parentNode->removeChild($node); } } } } }; foreach($words as $name => $word) $ps($D->documentElement, $word, $name); } $x = new DOMDocument(); $x->loadXML("<data>drugs cartel</data>"); applyHLToSiblings($x); var_dump($x->saveXML());

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.0150.00717.00
8.3.50.0100.01022.02
8.3.40.0060.00919.19
8.3.30.0150.00419.04
8.3.20.0040.00420.55
8.3.10.0080.00023.73
8.3.00.0040.00419.63
8.2.180.0120.00418.66
8.2.170.0110.00722.96
8.2.160.0110.00320.64
8.2.150.0080.00024.18
8.2.140.0000.00724.66
8.2.130.0060.00319.61
8.2.120.0000.00826.35
8.2.110.0120.00022.50
8.2.100.0080.00418.18
8.2.90.0050.00319.61
8.2.80.0040.00417.97
8.2.70.0040.00417.63
8.2.60.0080.00018.18
8.2.50.0000.01018.07
8.2.40.0040.00419.61
8.2.30.0070.00020.85
8.2.20.0030.00618.09
8.2.10.0070.00018.39
8.2.00.0080.00018.44
8.1.280.0070.01125.92
8.1.270.0060.00324.08
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0000.00822.82
8.1.230.0120.00018.02
8.1.220.0000.00817.79
8.1.210.0040.00418.77
8.1.200.0070.00317.73
8.1.190.0040.00417.48
8.1.180.0000.00818.10
8.1.170.0040.00419.01
8.1.160.0080.00022.36
8.1.150.0060.00319.11
8.1.140.0000.00819.80
8.1.130.0030.00317.98
8.1.120.0100.00017.73
8.1.110.0030.00517.79
8.1.100.0040.00417.65
8.1.90.0000.00717.77
8.1.80.0040.00417.75
8.1.70.0040.00417.76
8.1.60.0040.00417.98
8.1.50.0040.00417.88
8.1.40.0050.00317.86
8.1.30.0090.00018.06
8.1.20.0050.00318.03
8.1.10.0000.00717.86
8.1.00.0000.00917.91
8.0.300.0040.00418.77
8.0.290.0040.00417.13
8.0.280.0000.00718.79
8.0.270.0030.00317.60
8.0.260.0030.00617.58
8.0.250.0030.00317.45
8.0.240.0050.00217.41
8.0.230.0060.00317.26
8.0.220.0040.00417.36
8.0.210.0090.00017.30
8.0.200.0050.00217.25
8.0.190.0030.00617.39
8.0.180.0000.00817.38
8.0.170.0050.00317.23
8.0.160.0000.00717.34
8.0.150.0090.00017.14
8.0.140.0000.00717.31
8.0.130.0090.00013.72
8.0.120.0000.00817.27
8.0.110.0060.00317.33
8.0.100.0040.00417.30
8.0.90.0000.00817.41
8.0.80.0070.01017.29
8.0.70.0040.00417.36
8.0.60.0040.00417.40
8.0.50.0040.00417.41
8.0.30.0130.00517.38
8.0.20.0100.01917.44
8.0.10.0040.00417.41
8.0.00.0090.00917.07
7.4.330.0030.00317.08
7.4.320.0070.00016.80
7.4.300.0000.00616.77
7.4.290.0030.00316.98
7.4.280.0000.00716.93
7.4.270.0000.00716.75
7.4.260.0030.00316.72
7.4.250.0040.00416.64
7.4.240.0040.00416.90
7.4.230.0030.00316.91
7.4.220.0070.01716.76
7.4.210.0040.01116.99
7.4.200.0070.00016.89
7.4.160.0100.00716.77
7.4.150.0120.00617.40
7.4.140.0140.00817.86
7.4.130.0070.01216.86
7.4.120.0110.01216.76
7.4.110.0060.01216.78
7.4.100.0150.00616.97
7.4.90.0110.00716.81
7.4.80.0100.01319.39
7.4.70.0060.01216.80
7.4.60.0100.01316.96
7.4.50.0000.01216.73
7.4.40.0070.01116.95
7.4.30.0110.01116.83
7.4.00.0100.00715.15
7.3.330.0030.00313.64
7.3.320.0050.00213.67
7.3.310.0040.00416.60
7.3.300.0050.00216.69
7.3.290.0080.00716.64
7.3.280.0100.00916.65
7.3.270.0130.00617.40
7.3.260.0100.00716.74
7.3.250.0120.01016.80
7.3.240.0090.00916.80
7.3.230.0030.01416.70
7.3.210.0100.01316.71
7.3.200.0030.01216.66
7.3.190.0110.00716.70
7.3.180.0070.01016.97
7.3.170.0130.00316.81
7.3.160.0150.00416.84
7.2.330.0220.01517.04
7.2.320.0080.01117.02
7.2.310.0120.00917.00
7.2.300.0030.01517.05
7.2.290.0110.01116.75
7.2.60.0060.01016.89
7.2.00.0090.00619.58
7.1.200.0080.00816.02
7.1.100.0400.00318.26
7.1.70.0000.00817.32
7.1.60.0030.02119.36
7.1.50.0070.01317.14
7.1.00.0000.08022.63
7.0.200.0030.00316.77
7.0.60.0000.09020.00
7.0.50.0070.08318.10
7.0.40.0170.07720.41
7.0.30.0400.05320.32
7.0.20.0270.08020.30
7.0.10.0070.08720.19
7.0.00.0070.04720.29
5.6.280.0170.04021.04
5.6.210.0130.08320.91
5.6.200.0130.08318.38
5.6.190.0200.07020.50
5.6.180.0470.07720.78
5.6.170.0300.07320.65
5.6.160.0100.07320.69
5.6.150.0030.04318.37
5.6.140.0030.06718.23
5.6.130.0070.07718.38
5.6.120.0200.07321.13
5.6.110.0130.06321.22
5.6.100.0030.05321.21
5.6.90.0070.08721.15
5.6.80.0000.04320.44
5.5.350.4200.04320.45
5.5.340.0130.07318.02
5.5.330.0170.07720.33
5.5.320.0130.07720.46
5.5.310.0330.03720.45
5.5.300.0170.05718.05
5.5.290.0100.06718.11
5.5.280.0100.07320.91
5.5.270.0130.08320.90
5.5.260.0030.07020.88
5.5.250.0230.06020.90
5.5.240.0270.06720.36

preferences:
47.07 ms | 401 KiB | 5 Q