3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string_old = "This is the second div that we are using to check if the original data can be seen & Yes It is Working"; $string_new = "This is the first div that we are using to check if the changed data can be seen & Yes It is Working"; function getDiffed($string_old, $string_new){ $A = explode(" ", $string_old); $B = explode(" ", $string_new); $LCS = []; for($i = 0; $i < count($A); ++$i){ for($j = 0; $j < count($B); ++$j){ if($A[ $i ] == $B[ $j ]){ $LCS[ $i ][ $j ] = max($LCS[ $i ][ $j - 1 ] ?? 0, ($LCS[ $i - 1 ][ $j - 1 ] ?? 0) + 1); }else{ $LCS[ $i ][ $j ] = max($LCS[ $i - 1 ][ $j ] ?? 0, $LCS[ $i ][ $j - 1 ] ?? 0); } } } // get the LCS string space separated. $i = count($A) - 1; $j = count($B) - 1; $commonWords = []; while($i >= 0 && $j >= 0){ if($A[ $i ] == $B[ $j ]){ $commonWords[] = $A[ $i ]; $i--; $j--; }else if(($LCS[ $i ][$j - 1] ?? 0) > ($LCS[ $i - 1 ][ $j ] ?? 0)){ $j--; }else{ $i--; } } $commonWords = array_reverse($commonWords); // add red marks if any for the old string for($i = 0, $ptr = 0; $i < count($A); ++$i){ if($ptr == count($commonWords) || $A[ $i ] !== $commonWords[ $ptr ]){ $A[ $i ] = "<del style='background-color:#ffcccc'> " .$A[ $i ] . "</del>"; }else{ $ptr++; } } // add green marks if any for the new string for($i = 0, $ptr = 0; $i < count($B); ++$i){ if($ptr == count($commonWords) || $B[ $i ] !== $commonWords[ $ptr ]){ $B[ $i ] = "<ins style='background-color:#ccffcc'> " .$B[ $i ] . "</ins>"; }else{ $ptr++; } } return ['old' => implode(' ', $A), 'new' => implode(' ', $B)]; } $diff = getDiffed($string_old, $string_new); $doc = <<<DOC <center> <h2>Old String VS New String</h2> <table border=1 cellpadding=15> <tr align=center> <td>Old</td> <td>New</td> </tr> <tr> <td>$diff[old]</td> <td>$diff[new]</td> </tr> </table> </center> DOC; echo $doc;

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.5.10.0110.01119.30
8.5.00.0130.00820.22
8.4.150.0020.00114.05
8.4.140.0130.00817.60
8.4.130.0130.00717.71
8.4.120.0060.00320.93
8.4.110.0140.00822.63
8.4.100.0120.00917.82
8.4.90.0100.00720.73
8.4.80.0110.00918.75
8.4.70.0050.00417.96
8.4.60.0110.00718.73
8.4.50.0140.00618.52
8.4.40.0160.00017.83
8.4.30.0200.01118.27
8.4.20.0220.00717.67
8.4.10.0160.00819.76
8.3.280.0100.01320.28
8.3.270.0100.00916.70
8.3.260.0070.01216.39
8.3.250.0130.00619.14
8.3.240.0090.01017.30
8.3.230.0120.00716.65
8.3.220.0100.00918.91
8.3.210.0100.00916.64
8.3.200.0120.00916.52
8.3.190.0120.00617.41
8.3.180.0090.00616.53
8.3.170.0110.00720.74
8.3.160.0180.01117.46
8.3.150.0170.00816.82
8.3.140.0160.00716.67
8.3.130.0140.00816.58
8.3.120.0210.00517.80
8.3.110.0160.00517.07
8.3.100.0190.00316.52
8.3.90.0190.00619.02
8.3.80.0230.00416.76
8.3.70.0180.00516.53
8.3.60.0190.00416.49
8.3.50.0190.00616.58
8.3.40.0160.00818.73
8.3.30.0130.00618.20
8.3.20.0110.00721.38
8.3.10.0140.00419.31
8.3.00.0100.00420.11
8.2.290.0050.00420.47
8.2.280.0130.00818.50
8.2.270.0150.00717.58
8.2.260.0130.00916.57
8.2.250.0110.00817.05
8.2.240.0110.00816.66
8.2.230.0150.00617.57
8.2.220.0150.00418.37
8.2.210.0140.00519.02
8.2.200.0160.00316.94
8.2.190.0160.00616.93
8.2.180.0170.00516.70
8.2.170.0180.00517.96
8.2.160.0150.00718.92
8.2.150.0140.00619.58
8.2.140.0130.00620.58
8.2.130.0190.00419.65
8.2.120.0180.00418.39
8.2.110.0160.00418.43
8.2.100.0220.00517.59
8.2.90.0170.00417.67
8.2.80.0160.00317.94
8.2.70.0230.00517.60
8.2.60.0190.00717.58
8.2.50.0200.00817.65
8.2.40.0200.00417.91
8.2.30.0180.00417.63
8.2.20.0120.00918.08
8.2.10.0160.00417.57
8.2.00.0160.00517.59
8.1.330.0110.00722.00
8.1.320.0110.00916.41
8.1.310.0160.00616.96
8.1.300.0160.00716.25
8.1.290.0200.00420.13
8.1.280.0190.00718.45
8.1.270.0190.00618.86
8.1.260.0130.00519.45
8.1.250.0140.00319.96
8.1.240.0150.00818.21
8.1.230.0160.00418.39
8.1.220.0210.00517.38
8.1.210.0200.00717.52
8.1.200.0200.01017.34
8.1.190.0240.00517.34
8.1.180.0210.00517.30
8.1.170.0190.00617.32
8.1.160.0190.00517.66
8.1.150.0230.00417.34
8.1.140.0180.00917.29
8.1.130.0220.00517.35
8.1.120.0160.00617.38
8.1.110.0190.00417.49
8.1.100.0150.00617.33
8.1.90.0140.00817.37
8.1.80.0190.00417.59
8.1.70.0170.00617.38
8.1.60.0200.00517.31
8.1.50.0270.00517.35
8.1.40.0180.01117.38
8.1.30.0230.00517.46
8.1.20.0180.00517.46
8.1.10.0200.00317.44
8.1.00.0170.00517.38
8.0.300.0170.00217.35
8.0.290.0190.00516.87
8.0.280.0160.00717.00
8.0.270.0140.00916.85
8.0.260.0210.00416.90
8.0.250.0150.00616.92
8.0.240.0170.00716.89
8.0.230.0150.00416.97
8.0.220.0190.00416.83
8.0.210.0200.00716.90
8.0.200.0180.00916.93
8.0.190.0200.00816.91
8.0.180.0180.00716.87
8.0.170.0180.00817.00
8.0.160.0190.00516.89
8.0.150.0220.00616.89
8.0.140.0210.00416.82
8.0.130.0200.00616.77
8.0.120.0170.00716.72
8.0.110.0190.00616.79
8.0.100.0170.00616.87
8.0.90.0160.00417.05
8.0.80.0210.00716.86
8.0.70.0140.00916.79
8.0.60.0160.00716.83
8.0.50.0170.00816.74
8.0.30.0190.00416.86
8.0.20.0150.00616.98
8.0.10.0180.00417.00
7.4.00.0250.00816.39

preferences:
45.61 ms | 403 KiB | 5 Q