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); $before = $ms($name, $wrap); $newSpan->textContent = $wrap; !$before ?: $node->insertBefore($node->nextSibling, $mt($before)); $node->insertBefore($node->nextSibling, $ms($mt($wrap), $name)); !$after ?: $node->insertBefore($node->nextSibling, $mt($after)); } } } } }; 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.0110.00417.13
8.3.50.0140.00522.05
8.3.40.0000.01419.22
8.3.30.0110.00418.97
8.3.20.0050.00320.55
8.3.10.0040.00423.78
8.3.00.0090.00019.63
8.2.180.0160.00018.91
8.2.170.0090.00622.96
8.2.160.0070.00720.70
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0080.00017.99
8.2.120.0040.00426.35
8.2.110.0050.00520.63
8.2.100.0090.00318.05
8.2.90.0050.00319.47
8.2.80.0030.00517.97
8.2.70.0030.00717.75
8.2.60.0080.00018.29
8.2.50.0030.00618.07
8.2.40.0040.00419.64
8.2.30.0040.00420.82
8.2.20.0000.00818.05
8.2.10.0000.00818.48
8.2.00.0050.00318.39
8.1.280.0120.00325.92
8.1.270.0090.00324.14
8.1.260.0070.00028.09
8.1.250.0040.01128.09
8.1.240.0040.00424.05
8.1.230.0060.00619.69
8.1.220.0110.00017.74
8.1.210.0080.00018.77
8.1.200.0030.00617.72
8.1.190.0000.00817.60
8.1.180.0030.00518.10
8.1.170.0080.00019.04
8.1.160.0040.00422.33
8.1.150.0070.00019.16
8.1.140.0080.00019.83
8.1.130.0050.00217.93
8.1.120.0050.00517.76
8.1.110.0000.00817.79
8.1.100.0000.00717.76
8.1.90.0040.00417.58
8.1.80.0050.00317.79
8.1.70.0000.00717.68
8.1.60.0030.00617.92
8.1.50.0000.00917.94
8.1.40.0040.00417.85
8.1.30.0040.00417.85
8.1.20.0030.00517.97
8.1.10.0000.00817.93
8.1.00.0090.00317.90
8.0.300.0000.00718.77
8.0.290.0070.00017.00
8.0.280.0070.00018.74
8.0.270.0040.00317.54
8.0.260.0060.00317.54
8.0.250.0040.00417.18
8.0.240.0000.00817.20
8.0.230.0030.00617.36
8.0.220.0030.00317.18
8.0.210.0070.00017.29
8.0.200.0030.00317.18
8.0.190.0030.00617.38
8.0.180.0040.00417.10
8.0.170.0000.00717.15
8.0.160.0000.00717.21
8.0.150.0070.00417.08
8.0.140.0050.00317.09
8.0.130.0060.00313.61
8.0.120.0040.00417.30
8.0.110.0040.00417.18
8.0.100.0040.00417.11
8.0.90.0030.00517.17
8.0.80.0030.01317.26
8.0.70.0000.00817.11
8.0.60.0020.00517.07
8.0.50.0000.00716.99
8.0.30.0070.01217.39
8.0.20.0110.01117.47
8.0.10.0040.00417.22
8.0.00.0080.01017.09
7.4.330.0000.00516.99
7.4.320.0030.00316.75
7.4.300.0000.00616.85
7.4.290.0000.00716.61
7.4.280.0040.00416.63
7.4.270.0070.00016.75
7.4.260.0000.00716.72
7.4.250.0000.00716.80
7.4.240.0040.00416.81
7.4.230.0000.00816.93
7.4.220.0040.01416.84
7.4.210.0030.01416.75
7.4.200.0040.00416.70
7.4.160.0040.01116.75
7.4.150.0030.01517.40
7.4.140.0140.01117.86
7.4.130.0120.00716.77
7.4.120.0090.00816.84
7.4.110.0130.00616.89
7.4.100.0140.00716.85
7.4.90.0060.01216.84
7.4.80.0060.01219.39
7.4.70.0120.00916.66
7.4.60.0080.00816.76
7.4.50.0130.00616.65
7.4.40.0090.00916.77
7.4.30.0070.01016.84
7.4.00.0030.01215.04
7.3.330.0030.00313.73
7.3.320.0030.00313.51
7.3.310.0050.00316.55
7.3.300.0030.00316.64
7.3.290.0050.00916.62
7.3.280.0090.01116.67
7.3.270.0100.00617.40
7.3.260.0120.00616.68
7.3.250.0080.00916.70
7.3.240.0080.01016.72
7.3.230.0070.01016.58
7.3.210.0030.01416.78
7.3.200.0060.01516.89
7.3.190.0120.00616.67
7.3.180.0100.00616.72
7.3.170.0120.00416.88
7.3.160.0050.01516.89
7.3.10.0100.01016.22
7.3.00.0110.01116.60
7.2.330.0030.01917.01
7.2.320.0090.01316.93
7.2.310.0030.01316.92
7.2.300.0060.01016.69
7.2.290.0100.00616.94
7.2.130.0160.00616.46
7.2.120.0110.01316.70
7.2.110.0200.00016.96
7.2.100.0150.00716.27
7.2.90.0120.01116.96
7.2.80.0190.00316.35
7.2.70.0190.00016.47
7.2.60.0100.00416.68
7.2.50.0130.00616.88
7.2.40.0100.01016.91
7.2.30.0140.00716.62
7.2.20.0120.00316.75
7.2.10.0140.00716.55
7.2.00.0090.00518.36
7.1.250.0130.01315.19
7.1.200.0030.01215.75
7.1.100.0070.00418.32
7.1.70.0070.00017.43
7.1.60.0160.00619.36
7.1.50.0070.01517.28
7.1.00.0000.07722.56
7.0.200.0030.00517.02
7.0.60.0130.05319.99
7.0.50.0070.07318.06
7.0.40.0070.08020.36
7.0.30.0470.07720.17
7.0.20.0200.05020.29
7.0.10.0200.07720.29
7.0.00.0000.05320.30
5.6.280.0000.03321.05
5.6.210.0100.05020.92
5.6.200.0070.08018.38
5.6.190.0130.08320.80
5.6.180.0470.06020.85
5.6.170.0330.06720.58
5.6.160.0070.08320.54
5.6.150.0100.04318.20
5.6.140.0070.07318.26
5.6.130.0130.08018.30
5.6.120.0100.07321.21
5.6.110.0000.08721.14
5.6.100.0130.07721.18
5.6.90.0100.08021.18
5.6.80.0070.03720.51
5.5.350.4230.04020.48
5.5.340.0300.04318.02
5.5.330.0070.08720.21
5.5.320.0070.07320.45
5.5.310.0300.04320.42
5.5.300.0070.08318.15
5.5.290.0070.08318.16
5.5.280.0030.07720.75
5.5.270.0170.07720.90
5.5.260.0030.05021.01
5.5.250.0070.06320.76
5.5.240.0230.07720.26

preferences:
62.28 ms | 401 KiB | 5 Q