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";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 11
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 41
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 43
Branch analysis from position: 50
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 47
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 43
Branch analysis from position: 50
Branch analysis from position: 43
Branch analysis from position: 47
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 15
Branch analysis from position: 24
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 15
Branch analysis from position: 24
Branch analysis from position: 15
filename:       /in/X0Sif
function name:  (null)
number of ops:  62
compiled vars:  !0 = $string1, !1 = $string2, !2 = $len, !3 = $start, !4 = $i, !5 = $xor, !6 = $pos, !7 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'The+lazy+cat+jumps+over+the+fast+fox'
    3     1        ASSIGN                                                   !1, 'The+fast+fox+jumps+over+the+lazy+cat'
    5     2        STRLEN                                           ~10     !0
          3        ASSIGN                                                   !2, ~10
    6     4        DECLARE_CONST                                            'runs', 31337
    8     5        INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $12     
          8        ASSIGN                                                   !3, $12
    9     9        ASSIGN                                                   !4, 0
         10      > JMP                                                      ->24
   11    11    >   BW_XOR                                           ~15     !0, !1
         12        ASSIGN                                                   !5, ~15
   13    13        ASSIGN                                                   !6, 0
         14      > JMP                                                      ->16
   15    15    >   PRE_INC                                                  !6
   13    16    >   INIT_FCALL                                               'strspn'
         17        SEND_VAR                                                 !5
         18        SEND_VAL                                                 '%00'
         19        SEND_VAR                                                 !6
         20        DO_ICALL                                         $19     
         21        ASSIGN_OP                                     1  ~20     !6, $19
         22        IS_SMALLER                                               ~20, !2
         23      > JMPNZ                                                    ~21, ->15
    9    24    >   PRE_INC                                          ~22     !4
         25        FETCH_CONSTANT                                   ~23     'runs'
         26        IS_SMALLER                                               ~22, ~23
         27      > JMPNZ                                                    ~24, ->11
   18    28    >   INIT_FCALL                                               'microtime'
         29        SEND_VAL                                                 1
         30        DO_ICALL                                         $25     
         31        SUB                                              ~26     $25, !3
         32        CONCAT                                           ~27     'ircmax%27s+XOR%2Bstrspn+%2B+ka%27s+loop%3A%3Cbr%3E%0A', ~26
         33        CONCAT                                           ~28     ~27, 'sec%3Cbr%3E%0A%3Cbr%3E%0A'
         34        ECHO                                                     ~28
   21    35        INIT_FCALL                                               'microtime'
         36        SEND_VAL                                                 1
         37        DO_ICALL                                         $29     
         38        ASSIGN                                                   !3, $29
   22    39        ASSIGN                                                   !4, 0
         40      > JMP                                                      ->50
   24    41    >   ASSIGN                                                   !7, 0
         42      > JMP                                                      ->48
   25    43    >   FETCH_DIM_R                                      ~33     !0, !7
         44        FETCH_DIM_R                                      ~34     !1, !7
         45        IS_NOT_IDENTICAL                                         ~33, ~34
         46      > JMPZ                                                     ~35, ->47
   24    47    >   PRE_INC                                                  !7
         48    >   IS_SMALLER                                               !7, !2
         49      > JMPNZ                                                    ~37, ->43
   22    50    >   PRE_INC                                          ~38     !4
         51        FETCH_CONSTANT                                   ~39     'runs'
         52        IS_SMALLER                                               ~38, ~39
         53      > JMPNZ                                                    ~40, ->41
   30    54    >   INIT_FCALL                                               'microtime'
         55        SEND_VAL                                                 1
         56        DO_ICALL                                         $41     
         57        SUB                                              ~42     $41, !3
         58        CONCAT                                           ~43     'NikiC%27s+example+from+question+body%3A%3Cbr%3E%0A', ~42
         59        CONCAT                                           ~44     ~43, 'sec%3Cbr%3E%0A'
         60        ECHO                                                     ~44
         61      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.7 ms | 945 KiB | 18 Q