3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php 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); }
based on ZY0MT

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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.2.60.0070.00716.50
7.2.00.0030.00719.09
7.1.200.0040.00815.24
7.1.100.0150.00017.74
7.1.70.0020.00516.68
7.1.60.0110.01119.50
7.1.50.0090.00916.95
7.1.00.0000.07722.44
7.0.200.0780.00014.94
7.0.140.0100.06722.11
7.0.60.0030.08021.88
7.0.50.0100.07717.89
7.0.40.0000.04720.23
7.0.30.0130.04720.19
7.0.20.0200.08020.06
7.0.10.0300.08020.23
7.0.00.0070.05020.05
5.6.280.0100.06721.13
5.6.210.0100.07720.52
5.6.200.0030.04318.28
5.6.190.0030.07320.62
5.6.180.0230.08020.65
5.6.170.0370.07020.57
5.6.160.0000.04720.50
5.6.150.0070.08018.15
5.6.140.0170.07018.25
5.6.130.0030.07718.18
5.6.120.0030.07720.98
5.6.110.0130.05020.95
5.6.100.0100.08321.03
5.6.90.0170.06021.02
5.6.80.0030.05020.50
5.5.350.3200.04720.38
5.5.340.0070.05717.95
5.5.330.0100.04020.47
5.5.320.0100.08020.27
5.5.310.0330.05320.27
5.5.300.0170.07017.94
5.5.290.0070.07017.93
5.5.280.0100.03320.79
5.5.270.0200.07020.77
5.5.260.0070.08320.82
5.5.250.0100.06320.79
5.5.240.0270.04320.28
5.4.450.0730.09019.61
5.4.440.0730.05719.61
5.4.430.0930.05019.54
5.4.420.0670.06019.46
5.4.410.1000.05019.49
5.4.400.0570.06018.53
5.4.390.0370.04718.53
5.4.380.0430.07018.81
5.4.370.0530.05718.79
5.4.360.0330.04718.49
5.4.350.0370.05318.60
5.4.340.0430.04318.49
5.4.320.0300.05718.61
5.4.310.0300.07018.52
5.4.300.0330.06718.82
5.4.290.0300.06718.75
5.4.280.0330.07018.74
5.4.270.0300.06018.57
5.4.260.0400.05318.64
5.4.250.0300.06718.84
5.4.240.0470.06018.76
5.4.230.0230.05318.54
5.4.220.0330.04718.76
5.4.210.0430.05318.75
5.4.200.0270.05716.62
5.4.190.0300.06018.77
5.4.180.0400.07318.56
5.4.170.0330.07318.79
5.4.160.0270.05718.76
5.4.150.0300.06018.78
5.4.140.0200.06316.48
5.4.130.0200.05316.41
5.4.120.0270.05016.34
5.4.110.0200.05316.25
5.4.100.0330.06716.30
5.4.90.0270.07016.30
5.4.80.0270.06716.22
5.4.70.0270.04316.21
5.4.60.0330.04316.26
5.4.50.0400.04716.17
5.4.40.0200.05716.25
5.4.30.0270.04316.43
5.4.20.0230.06716.24
5.4.10.0200.04716.27
5.4.00.0170.06015.80
5.3.290.0200.05714.79
5.3.280.0370.03714.70
5.3.270.0130.07014.71
5.3.260.0270.05314.66
5.3.250.0130.06314.59
5.3.240.0300.04714.82
5.3.230.0300.04314.63
5.3.220.0230.04314.75
5.3.210.0200.05314.61
5.3.200.0200.05314.61
5.3.190.0170.05714.68
5.3.180.0130.05714.55
5.3.170.0200.05014.61
5.3.160.0230.04714.61
5.3.150.0200.05314.70
5.3.140.0230.05014.66
5.3.130.0330.04714.73
5.3.120.0200.05714.67
5.3.110.0230.05714.68
5.3.100.0130.05714.09
5.3.90.0300.04314.04
5.3.80.0200.05013.99
5.3.70.0200.05714.12
5.3.60.0200.05314.05
5.3.50.0200.05014.05
5.3.40.0200.05013.98
5.3.30.0300.04014.02
5.3.20.0230.04713.69
5.3.10.0170.05013.86
5.3.00.0130.05713.68
5.2.170.0170.04311.25
5.2.160.0200.04011.37
5.2.150.0200.04011.20
5.2.140.0330.03011.23
5.2.130.0230.04011.20
5.2.120.0200.03711.22
5.2.110.0130.04311.21
5.2.100.0230.03311.12
5.2.90.0230.04311.17
5.2.80.0200.04011.12
5.2.70.0200.04311.13
5.2.60.0200.04011.11
5.2.50.0270.05311.01
5.2.40.0230.04711.07
5.2.30.0100.05010.97
5.2.20.0200.03711.04
5.2.10.0170.04010.91
5.2.00.0200.05010.76
5.1.60.0170.03310.13
5.1.50.0170.03010.03
5.1.40.0230.03710.15
5.1.30.0130.04010.36
5.1.20.0130.04010.38
5.1.10.0200.03010.14
5.1.00.0070.04310.11
5.0.50.0130.0238.64
5.0.40.0130.0238.59
5.0.30.0070.0478.27
5.0.20.0100.0308.33
5.0.10.0070.0308.28
5.0.00.0070.0478.19
4.4.90.0070.0235.98
4.4.80.0070.0205.97
4.4.70.0100.0235.95
4.4.60.0070.0205.91
4.4.50.0100.0205.95
4.4.40.0170.0305.89
4.4.30.0100.0205.89
4.4.20.0030.0275.95
4.4.10.0130.0175.98
4.4.00.0070.0375.95
4.3.110.0070.0235.86
4.3.100.0130.0135.80
4.3.90.0030.0235.87
4.3.80.0130.0275.83
4.3.70.0030.0235.83
4.3.60.0100.0175.81
4.3.50.0100.0205.80
4.3.40.0030.0405.79
4.3.30.0100.0174.56
4.3.20.0070.0204.54
4.3.10.0000.0274.50
4.3.00.0130.0207.32