3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string1 = 'The lazy cat jumps over the fast fox'; $string2 = 'The fast fox jumps over the lazy cat'; $len=strlen($string1); const runs=31337; $start=microtime(1); $i=0;while (++$i<runs) { $xor = $string1 ^ $string2; $pos=0;while(($pos+=strspn($xor,"\0",$pos))<$len) { // print 'Diff @'.$pos.' String1:'.$string1[$pos].' String2:'.$string2[$pos]." <br>\n"; $pos++; } } print "ircmax's XOR+strspn + ka's loop:<br>\n".(microtime(1)-$start)."sec<br>\n<br>\n"; $start=microtime(1); $i=0;while (++$i<runs) { for ($offset = 0; $offset < $len; ++$offset) { if ($string1[$offset] !== $string2[$offset]) { //print 'Diff @'.$offset.' String1:'.$string1[$offset].' String2:'.$string2[$offset]." <br>\n"; } } } print "NikiC's example from question body:<br>\n".(microtime(1)-$start)."sec<br>\n";

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)
7.2.00.0100.05919.09
7.1.70.0030.11516.92
7.1.60.0100.09219.40
7.1.50.0070.11516.79
7.1.00.0000.20022.54
7.0.200.0700.11414.67
7.0.140.0070.20322.01
7.0.120.0030.21322.14
7.0.60.0070.13719.98
7.0.50.0100.19317.88
7.0.40.0130.18020.09
7.0.30.0330.17020.13
7.0.20.0200.13320.18
7.0.10.0100.12320.00
7.0.00.0070.19320.09
5.6.280.0100.29721.04
5.6.210.0130.25720.56
5.6.200.0030.24018.08
5.6.190.0100.21720.57
5.6.180.0200.20020.27
5.6.170.0270.28320.45
5.6.160.0100.25020.38
5.6.150.0070.21718.22
5.6.140.0100.27018.09
5.6.130.0030.20318.18
5.6.120.0030.27720.98
5.6.110.0000.26021.16
5.6.100.0130.24020.88
5.6.90.0130.25720.95
5.6.80.0130.24720.35
5.5.350.0270.25720.30
5.5.340.0030.24718.02
5.5.330.0030.21320.17
5.5.320.0130.20720.20
5.5.310.0230.26320.32
5.5.300.0100.24017.91
5.5.290.0130.22018.00
5.5.280.0030.27720.77
5.5.270.0070.21020.88
5.5.260.0000.26020.88
5.5.250.0070.27020.66
5.5.240.0000.17720.27
5.4.450.0030.21319.51
5.4.440.0030.20319.42
5.4.430.0030.26719.09
5.4.420.0070.25019.24
5.4.410.0000.27719.31
5.4.400.0030.27018.81
5.4.390.0030.26318.80
5.4.380.0030.20319.00
5.4.370.0070.24719.18
5.4.360.0130.25719.21
5.4.350.0000.26719.01
5.4.340.0070.23719.18
5.4.320.0070.19718.92
5.4.310.0100.25318.78
5.4.300.0100.26718.91
5.4.290.0800.21018.80
5.4.280.0000.22019.08
5.4.270.0030.25719.00
5.4.260.0100.21019.18
5.4.250.0130.21719.15
5.4.240.0070.23719.07
5.4.230.0000.22019.00
5.4.220.0100.30319.08
5.4.210.0070.26019.17
5.4.200.0070.26318.80
5.4.190.0070.24719.07
5.4.180.0170.22319.20
5.4.170.0600.21319.07
5.4.160.0100.22319.13
5.4.150.0130.26319.16
5.4.140.0000.26716.22
5.4.130.0100.26016.47
5.4.120.0070.25316.25
5.4.110.0070.24016.41
5.4.100.0000.26016.34
5.4.90.0000.28016.32
5.4.80.0070.20016.40
5.4.70.0030.22316.26
5.4.60.0100.25316.30
5.4.50.0030.22016.25
5.4.40.0070.26716.34
5.4.30.0070.21316.21
5.4.20.0070.26016.20
5.4.10.0070.25316.20
5.4.00.0070.24315.79
5.3.290.0000.30314.62
5.3.280.0030.30714.50
5.3.270.0070.32014.57
5.3.260.0100.31314.54
5.3.250.0130.29714.49
5.3.240.0000.24714.53
5.3.230.0070.30714.50
5.3.220.0070.24714.44
5.3.210.0000.25314.50
5.3.200.0030.31314.50
5.3.190.0000.27714.58
5.3.180.0070.30314.48
5.3.170.0100.27014.50
5.3.160.0070.30714.50
5.3.150.0030.26714.49
5.3.140.0100.26314.50
5.3.130.0030.29014.48
5.3.120.0070.26714.46
5.3.110.0070.30714.52
5.3.100.0070.29713.98
5.3.90.0000.27313.95
5.3.80.0070.30713.99
5.3.70.0130.26013.94
5.3.60.0100.24713.93
5.3.50.0100.32013.87
5.3.40.0070.26713.88
5.3.30.0000.27313.76
5.3.20.0100.29313.63
5.3.10.0070.30013.45
5.3.00.0030.24013.48
5.2.170.0000.07311.05
5.2.160.0030.06711.05
5.2.150.0030.04010.98
5.2.140.0000.05311.13
5.2.130.0030.05011.18
5.2.120.0130.05310.96
5.2.110.0070.04011.03
5.2.100.0100.02011.09
5.2.90.0000.06010.99
5.2.80.0000.04711.07
5.2.70.0000.03710.98
5.2.60.0070.06011.05
5.2.50.0100.03710.95
5.2.40.0070.04010.92
5.2.30.0000.05710.95
5.2.20.0030.04310.81
5.2.10.0130.04310.94
5.2.00.0030.04010.78
5.1.60.0070.0479.89
5.1.50.0070.03010.14
5.1.40.0100.0439.82
5.1.30.0000.02710.29
5.1.20.0070.02310.34
5.1.10.0000.03310.06
5.1.00.0030.05310.08
5.0.50.0030.0478.53
5.0.40.0130.0208.39
5.0.30.0030.0678.13
5.0.20.0000.0408.19
5.0.10.0030.0338.14
5.0.00.0070.0508.12
4.4.90.0100.0307.81
4.4.80.0000.0337.81
4.4.70.0030.0277.81
4.4.60.0030.0307.81
4.4.50.0030.0377.81
4.4.40.0030.0577.81
4.4.30.0030.0377.81
4.4.20.0070.0307.81
4.4.10.0030.0337.81
4.4.00.0030.0477.81
4.3.110.0100.0137.81
4.3.100.0100.0277.81
4.3.90.0030.0337.81
4.3.80.0030.0477.81
4.3.70.0000.0307.81
4.3.60.0000.0207.81
4.3.50.0000.0377.81
4.3.40.0000.0307.81
4.3.30.0000.0237.81
4.3.20.0000.0207.81
4.3.10.0000.0207.81
4.3.00.0030.0137.81

preferences:
35.37 ms | 401 KiB | 5 Q