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($name, $content = null) 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.0170.00318.70
8.3.50.0120.00722.24
8.3.40.0140.00018.90
8.3.30.0070.00719.14
8.3.20.0050.00220.47
8.3.10.0060.00323.96
8.3.00.0040.00419.51
8.2.180.0130.00317.00
8.2.170.0030.01322.96
8.2.160.0100.00720.60
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00817.88
8.2.120.0050.00326.35
8.2.110.0120.00022.51
8.2.100.0000.01118.18
8.2.90.0030.00619.42
8.2.80.0050.00317.97
8.2.70.0000.00817.88
8.2.60.0030.00518.15
8.2.50.0040.00818.07
8.2.40.0000.00819.66
8.2.30.0020.00520.84
8.2.20.0030.00618.05
8.2.10.0040.00418.52
8.2.00.0050.00318.30
8.1.280.0070.01125.92
8.1.270.0090.00024.04
8.1.260.0000.00828.09
8.1.250.0040.00428.09
8.1.240.0080.00022.65
8.1.230.0090.00318.14
8.1.220.0040.00418.01
8.1.210.0030.00618.77
8.1.200.0030.00617.63
8.1.190.0000.00817.38
8.1.180.0050.00318.10
8.1.170.0040.00418.88
8.1.160.0070.00022.18
8.1.150.0060.00319.20
8.1.140.0050.00319.71
8.1.130.0040.00417.94
8.1.120.0030.00717.65
8.1.110.0030.00517.80
8.1.100.0040.00417.75
8.1.90.0040.00417.56
8.1.80.0000.00717.61
8.1.70.0030.00517.70
8.1.60.0060.00317.91
8.1.50.0000.00917.77
8.1.40.0050.00317.85
8.1.30.0030.00618.01
8.1.20.0060.00317.98
8.1.10.0040.00417.80
8.1.00.0110.00017.77
8.0.300.0080.00019.09
8.0.290.0050.00217.00
8.0.280.0030.00318.73
8.0.270.0030.00317.59
8.0.260.0040.00417.53
8.0.250.0070.00017.38
8.0.240.0000.00817.27
8.0.230.0060.00317.28
8.0.220.0040.00417.15
8.0.210.0040.00417.15
8.0.200.0000.00717.20
8.0.190.0040.00417.39
8.0.180.0040.00417.12
8.0.170.0000.00817.25
8.0.160.0040.00417.22
8.0.150.0040.00417.34
8.0.140.0050.00517.15
8.0.130.0060.00313.71
8.0.120.0080.00017.14
8.0.110.0040.00417.14
8.0.100.0000.00717.24
8.0.90.0070.00017.30
8.0.80.0070.01017.18
8.0.70.0000.00917.11
8.0.60.0000.00817.31
8.0.50.0040.00417.25
8.0.30.0080.01117.18
8.0.20.0090.01517.41
8.0.10.0040.00417.05
8.0.00.0080.01117.12
7.4.330.0020.00216.96
7.4.320.0030.00316.76
7.4.300.0030.00316.74
7.4.290.0000.00716.75
7.4.280.0000.00716.83
7.4.270.0040.00416.83
7.4.260.0000.00816.81
7.4.250.0040.00416.74
7.4.240.0020.00516.88
7.4.230.0050.00316.79
7.4.220.0040.01716.84
7.4.210.0170.00716.67
7.4.200.0000.00716.81
7.4.160.0150.00016.55
7.4.150.0090.01217.40
7.4.140.0140.01117.86
7.4.130.0120.00616.81
7.4.120.0120.00816.70
7.4.110.0000.01816.61
7.4.100.0140.00316.73
7.4.90.0130.00316.76
7.4.80.0030.02019.39
7.4.70.0120.00916.84
7.4.60.0140.00316.67
7.4.50.0150.00316.92
7.4.40.0080.01216.73
7.4.30.0030.01316.68
7.4.00.0060.00915.34
7.3.330.0000.00513.66
7.3.320.0040.00413.51
7.3.310.0000.00816.69
7.3.300.0070.00016.66
7.3.290.0130.00516.65
7.3.280.0100.00616.69
7.3.270.0000.02117.40
7.3.260.0130.00416.57
7.3.250.0100.00716.74
7.3.240.0110.00916.68
7.3.230.0110.00916.56
7.3.210.0060.01616.66
7.3.200.0060.01316.76
7.3.190.0150.00616.84
7.3.180.0060.01016.71
7.3.170.0160.00016.65
7.3.160.0030.01516.76
7.2.330.0260.02316.85
7.2.320.0120.00917.00
7.2.310.0070.01017.13
7.2.300.0040.01417.04
7.2.290.0130.00316.72
7.2.60.0000.01317.00
7.2.00.0030.00919.89
7.1.200.0100.00315.92
7.1.100.0040.00718.57
7.1.70.0040.00417.11
7.1.60.0060.01619.36
7.1.50.0040.00817.28
7.1.00.0000.07722.55
7.0.200.0040.00716.95
7.0.60.0030.08020.07
7.0.50.0070.06718.04
7.0.40.0130.08020.20
7.0.30.0500.07320.32
7.0.20.0270.07720.16
7.0.10.0030.09320.37
7.0.00.0130.04720.36
5.6.280.0030.03021.21
5.6.210.0070.08720.57
5.6.200.0070.08718.20
5.6.190.0030.09320.70
5.6.180.0430.07720.53
5.6.170.0200.06320.57
5.6.160.0070.08020.64
5.6.150.0100.04318.19
5.6.140.0030.06018.25
5.6.130.0130.07718.38
5.6.120.0030.05721.23
5.6.110.0070.09021.24
5.6.100.0100.09021.13
5.6.90.0030.08721.18
5.6.80.0130.03320.54
5.5.350.4270.04320.61
5.5.340.0070.08317.99
5.5.330.0030.05020.32
5.5.320.0070.07320.35
5.5.310.0300.06020.37
5.5.300.0070.04018.11
5.5.290.0130.06018.18
5.5.280.0170.07020.91
5.5.270.0070.06321.07
5.5.260.0030.06020.80
5.5.250.0100.08020.70
5.5.240.0270.06320.34

preferences:
49.25 ms | 401 KiB | 5 Q