3v4l.org

run code in 300+ PHP versions simultaneously
<?php final function doCharDiff($from_text, $to_text) { $result = []; $jobs = [[0, strlen($from_text), 0, strlen($to_text)]]; while ($job = array_pop($jobs)) { // get the segments which must be diff'ed list($from_segment_start, $from_segment_end, $to_segment_start, $to_segment_end) = $job; $from_segment_len = $from_segment_end - $from_segment_start; $to_segment_len = $to_segment_end - $to_segment_start; // catch easy cases first if (!$from_segment_len || !$to_segment_len) { if ($from_segment_len) $result[$from_segment_start * 4 + 0] = new FineDiffDeleteOp($from_segment_len); else if ($to_segment_len) $result[$from_segment_start * 4 + 1] = new FineDiffInsertOp(substr($to_text, $to_segment_start, $to_segment_len)); continue; } if ($from_segment_len >= $to_segment_len) { $copy_len = $to_segment_len; while ($copy_len) { $to_copy_start = $to_segment_start; $to_copy_start_max = $to_segment_end - $copy_len; while ($to_copy_start <= $to_copy_start_max) { $from_copy_start = strpos(substr($from_text, $from_segment_start, $from_segment_len), substr($to_text, $to_copy_start, $copy_len)); if ($from_copy_start !== false) { $from_copy_start += $from_segment_start; break 2; } $to_copy_start++; } $copy_len--; } } else { $copy_len = $from_segment_len; while ($copy_len) { $from_copy_start = $from_segment_start; $from_copy_start_max = $from_segment_end - $copy_len; while ($from_copy_start <= $from_copy_start_max) { $to_copy_start = strpos(substr($to_text, $to_segment_start, $to_segment_len), substr($from_text, $from_copy_start, $copy_len)); if ($to_copy_start !== false) { $to_copy_start += $to_segment_start; break 2; } $from_copy_start++; } $copy_len--; } } // match found if ($copy_len) { $jobs[] = [$from_segment_start, $from_copy_start, $to_segment_start, $to_copy_start]; $result[$from_copy_start * 4 + 2] = new FineDiffCopyOp($copy_len); $jobs[] = [$from_copy_start + $copy_len, $from_segment_end, $to_copy_start + $copy_len, $to_segment_end]; } // no match, so delete all, insert all else { $result[$from_segment_start * 4] = new FineDiffReplaceOp($from_segment_len, substr($to_text, $to_segment_start, $to_segment_len)); } } ksort($result, SORT_NUMERIC); return array_values($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)
5.6.80.0100.06020.53
5.5.240.0070.07020.15
5.4.400.0330.05018.75
5.4.390.0230.06318.84
5.4.380.0170.05718.51
5.4.370.0270.05018.63
5.4.360.0230.05018.79
5.4.350.0300.05718.79
5.4.340.0170.05718.46
5.4.320.0370.06318.52
5.4.310.0330.05018.80
5.4.300.0300.06318.85
5.4.290.0200.06318.52
5.4.280.0170.06318.46
5.4.270.0270.05318.63
5.4.260.0200.05718.79
5.4.250.0200.06318.55
5.4.240.0170.06018.72
5.4.230.0330.05318.56
5.4.220.0230.05718.73
5.4.210.0630.06718.71
5.4.200.0900.04716.78
5.4.190.0330.05318.79
5.4.180.0230.06018.49
5.4.170.0700.07318.68
5.4.160.0500.04318.59
5.4.150.0330.06018.76
5.4.140.0330.04016.24
5.4.130.0300.04316.25
5.4.120.0300.05716.40
5.4.110.0330.05316.21
5.4.100.0370.06316.24
5.4.90.0370.04716.45
5.4.80.0300.04716.42
5.4.70.0270.05316.29
5.4.60.0400.04716.16
5.4.50.0400.05016.26
5.4.40.0430.04716.17
5.4.30.0470.04716.34
5.4.20.0400.05316.15
5.4.10.0370.07016.29
5.4.00.0430.04715.64
5.3.290.0430.06314.60
5.3.280.0370.05714.69
5.3.270.0330.06014.61
5.3.260.0500.05314.60
5.3.250.0270.06014.68
5.3.240.0370.05314.50
5.3.230.0430.05714.57
5.3.220.0470.07714.56
5.3.210.0400.07014.48
5.3.200.0370.05714.48
5.3.190.0500.05314.56
5.3.180.0300.06014.54
5.3.170.0370.05314.57
5.3.160.0430.04314.54
5.3.150.0300.05714.56
5.3.140.0530.05314.47
5.3.130.0530.06314.46
5.3.120.0300.05314.56
5.3.110.0330.04714.44
5.3.100.0470.05014.04
5.3.90.0370.06014.12
5.3.80.0330.06014.11
5.3.70.0400.06013.91
5.3.60.0430.06313.91
5.3.50.0430.05313.88
5.3.40.0400.04313.91
5.3.30.0530.06013.82
5.3.20.0470.05313.59
5.3.10.0400.04313.76
5.3.00.0500.04013.73
5.2.170.0230.04011.10
5.2.160.0300.04311.18
5.2.150.0300.04311.28
5.2.140.0300.06311.11
5.2.130.0400.05311.08
5.2.120.0430.05011.07
5.2.110.0270.05711.07
5.2.100.0300.04311.11
5.2.90.0270.05311.09
5.2.80.0200.06011.13
5.2.70.0170.04311.05
5.2.60.0230.04311.09
5.2.50.0170.04710.98
5.2.40.0300.03710.91
5.2.30.0170.04310.94
5.2.20.0100.04310.94
5.2.10.0270.04710.92
5.2.00.0300.05710.76
5.1.60.0270.04010.11
5.1.50.0200.0409.95
5.1.40.0100.04010.11
5.1.30.0170.04010.30
5.1.20.0270.03310.49
5.1.10.0200.03310.05
5.1.00.0230.02710.14
5.0.50.0130.0278.64
5.0.40.0170.0238.53
5.0.30.0070.0478.32
5.0.20.0070.0308.39
5.0.10.0100.0278.17
5.0.00.0170.0378.24
4.4.90.0170.0175.92
4.4.80.0030.0275.81
4.4.70.0070.0235.82
4.4.60.0070.0305.85
4.4.50.0100.0305.87
4.4.40.0100.0375.88
4.4.30.0070.0235.89
4.4.20.0000.0275.95
4.4.10.0070.0275.96
4.4.00.0070.0435.92
4.3.110.0070.0275.85
4.3.100.0000.0275.80
4.3.90.0070.0205.86
4.3.80.0130.0375.81
4.3.70.0070.0235.82
4.3.60.0070.0235.79
4.3.50.0030.0275.78
4.3.40.0100.0305.79
4.3.30.0100.0234.59
4.3.20.0070.0204.55
4.3.10.0030.0234.59
4.3.00.0030.0277.32

preferences:
146.43 ms | 1394 KiB | 7 Q