3v4l.org

run code in 300+ PHP versions simultaneously
<?php function snake($k,$y,$str1,$str2){ $x = $y - $k; while($x < mb_strlen($str1) && $y < mb_strlen($str2) && $str1[$x] == $str2[$y]){ $x++; $y++; } return $y; } function edit_distance_onp($str1, $str2){ $s1 = mb_strlen($str1) > mb_strlen($str2) ? $str2 : $str1; $s2 = mb_strlen($str1) > mb_strlen($str2) ? $str1 : $str2; $fp = array(); $x = 0; $y = 0; $k = 0; $p = 0; $offset = mb_strlen($s1) + 1; $delta = mb_strlen($s2) - mb_strlen($s1); for ($i = 0; $i < SIZE; $i++) $fp[$i] = -1; for ($p = 0; $fp[$delta + $offset] != mb_strlen($s2); $p++) { for($k = -$p; $k < $delta; $k++) $fp[$k + $offset] = snake($k, max($fp[$k-1+$offset] + 1, $fp[$k+1+$offset]), $s1, $s2); for($k = $delta + $p; $k > $delta; $k--) $fp[$k + $offset] = snake($k, max($fp[$k-1+$offset] + 1, $fp[$k+1+$offset]), $s1, $s2); $fp[$delta + $offset] = snake($delta, max($fp[$delta-1+$offset] + 1, $fp[$delta+1+$offset]), $s1, $s2); } return $delta + ($p - 1) * 2; } $cha1 = "aaa"; $cha2 = "bbb"; echo edit_distance_onp($cha1,$cha2); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FM403
function name:  (null)
number of ops:  8
compiled vars:  !0 = $cha1, !1 = $cha2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, 'aaa'
   32     1        ASSIGN                                                   !1, 'bbb'
   33     2        INIT_FCALL                                               'edit_distance_onp'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
   34     7      > RETURN                                                   1

Function snake:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 7
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
Branch analysis from position: 19
Branch analysis from position: 24
Branch analysis from position: 19
filename:       /in/FM403
function name:  snake
number of ops:  27
compiled vars:  !0 = $k, !1 = $y, !2 = $str1, !3 = $str2, !4 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    3     4        SUB                                              ~5      !1, !0
          5        ASSIGN                                                   !4, ~5
    4     6      > JMP                                                      ->9
    5     7    >   PRE_INC                                                  !4
    6     8        PRE_INC                                                  !1
    4     9    >   INIT_FCALL                                               'mb_strlen'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $9      
         12        IS_SMALLER                                       ~10     !4, $9
         13      > JMPZ_EX                                          ~10     ~10, ->19
         14    >   INIT_FCALL                                               'mb_strlen'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $11     
         17        IS_SMALLER                                       ~12     !1, $11
         18        BOOL                                             ~10     ~12
         19    > > JMPZ_EX                                          ~10     ~10, ->24
         20    >   FETCH_DIM_R                                      ~13     !2, !4
         21        FETCH_DIM_R                                      ~14     !3, !1
         22        IS_EQUAL                                         ~15     ~13, ~14
         23        BOOL                                             ~10     ~15
         24    > > JMPNZ                                                    ~10, ->7
    8    25    > > RETURN                                                   !1
    9    26*     > RETURN                                                   null

End of function snake

Function edit_distance_onp:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 46
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 127
Branch analysis from position: 127
2 jumps found. (Code = 44) Position 1 = 134, Position 2 = 54
Branch analysis from position: 134
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 57
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 104
Branch analysis from position: 104
2 jumps found. (Code = 44) Position 1 = 106, Position 2 = 83
Branch analysis from position: 106
2 jumps found. (Code = 44) Position 1 = 134, Position 2 = 54
Branch analysis from position: 134
Branch analysis from position: 54
Branch analysis from position: 83
2 jumps found. (Code = 44) Position 1 = 106, Position 2 = 83
Branch analysis from position: 106
Branch analysis from position: 83
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 80, Position 2 = 57
Branch analysis from position: 80
Branch analysis from position: 57
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 46
Branch analysis from position: 52
Branch analysis from position: 46
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
Branch analysis from position: 24
filename:       /in/FM403
function name:  edit_distance_onp
number of ops:  139
compiled vars:  !0 = $str1, !1 = $str2, !2 = $s1, !3 = $s2, !4 = $fp, !5 = $x, !6 = $y, !7 = $k, !8 = $p, !9 = $offset, !10 = $delta, !11 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        INIT_FCALL                                               'mb_strlen'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $12     
          5        INIT_FCALL                                               'mb_strlen'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $13     
          8        IS_SMALLER                                               $13, $12
          9      > JMPZ                                                     ~14, ->12
         10    >   QM_ASSIGN                                        ~15     !1
         11      > JMP                                                      ->13
         12    >   QM_ASSIGN                                        ~15     !0
         13    >   ASSIGN                                                   !2, ~15
   12    14        INIT_FCALL                                               'mb_strlen'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $17     
         17        INIT_FCALL                                               'mb_strlen'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $18     
         20        IS_SMALLER                                               $18, $17
         21      > JMPZ                                                     ~19, ->24
         22    >   QM_ASSIGN                                        ~20     !0
         23      > JMP                                                      ->25
         24    >   QM_ASSIGN                                        ~20     !1
         25    >   ASSIGN                                                   !3, ~20
   13    26        ASSIGN                                                   !4, <array>
   14    27        ASSIGN                                                   !5, 0
   15    28        ASSIGN                                                   !6, 0
   16    29        ASSIGN                                                   !7, 0
   17    30        ASSIGN                                                   !8, 0
   18    31        INIT_FCALL                                               'mb_strlen'
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                         $27     
         34        ADD                                              ~28     $27, 1
         35        ASSIGN                                                   !9, ~28
   19    36        INIT_FCALL                                               'mb_strlen'
         37        SEND_VAR                                                 !3
         38        DO_ICALL                                         $30     
         39        INIT_FCALL                                               'mb_strlen'
         40        SEND_VAR                                                 !2
         41        DO_ICALL                                         $31     
         42        SUB                                              ~32     $30, $31
         43        ASSIGN                                                   !10, ~32
   20    44        ASSIGN                                                   !11, 0
         45      > JMP                                                      ->49
   21    46    >   ASSIGN_DIM                                               !4, !11
         47        OP_DATA                                                  -1
   20    48        PRE_INC                                                  !11
         49    >   FETCH_CONSTANT                                   ~37     'SIZE'
         50        IS_SMALLER                                               !11, ~37
         51      > JMPNZ                                                    ~38, ->46
   22    52    >   ASSIGN                                                   !8, 0
         53      > JMP                                                      ->127
   23    54    >   MUL                                              ~40     !8, -1
         55        ASSIGN                                                   !7, ~40
         56      > JMP                                                      ->78
   24    57    >   ADD                                              ~42     !7, !9
         58        INIT_FCALL                                               'snake'
         59        SEND_VAR                                                 !7
         60        INIT_FCALL                                               'max'
         61        SUB                                              ~44     !7, 1
         62        ADD                                              ~45     ~44, !9
         63        FETCH_DIM_R                                      ~46     !4, ~45
         64        ADD                                              ~47     ~46, 1
         65        SEND_VAL                                                 ~47
         66        ADD                                              ~48     !7, 1
         67        ADD                                              ~49     ~48, !9
         68        FETCH_DIM_R                                      ~50     !4, ~49
         69        SEND_VAL                                                 ~50
         70        DO_ICALL                                         $51     
         71        SEND_VAR                                                 $51
         72        SEND_VAR                                                 !2
         73        SEND_VAR                                                 !3
         74        DO_FCALL                                      0  $52     
         75        ASSIGN_DIM                                               !4, ~42
         76        OP_DATA                                                  $52
   23    77        PRE_INC                                                  !7
         78    >   IS_SMALLER                                               !7, !10
         79      > JMPNZ                                                    ~54, ->57
   25    80    >   ADD                                              ~55     !10, !8
         81        ASSIGN                                                   !7, ~55
         82      > JMP                                                      ->104
   26    83    >   ADD                                              ~57     !7, !9
         84        INIT_FCALL                                               'snake'
         85        SEND_VAR                                                 !7
         86        INIT_FCALL                                               'max'
         87        SUB                                              ~59     !7, 1
         88        ADD                                              ~60     ~59, !9
         89        FETCH_DIM_R                                      ~61     !4, ~60
         90        ADD                                              ~62     ~61, 1
         91        SEND_VAL                                                 ~62
         92        ADD                                              ~63     !7, 1
         93        ADD                                              ~64     ~63, !9
         94        FETCH_DIM_R                                      ~65     !4, ~64
         95        SEND_VAL                                                 ~65
         96        DO_ICALL                                         $66     
         97        SEND_VAR                                                 $66
         98        SEND_VAR                                                 !2
         99        SEND_VAR                                                 !3
        100        DO_FCALL                                      0  $67     
        101        ASSIGN_DIM                                               !4, ~57
        102        OP_DATA                                                  $67
   25   103        PRE_DEC                                                  !7
        104    >   IS_SMALLER                                               !10, !7
        105      > JMPNZ                                                    ~69, ->83
   27   106    >   ADD                                              ~70     !10, !9
        107        INIT_FCALL                                               'snake'
        108        SEND_VAR                                                 !10
        109        INIT_FCALL                                               'max'
        110        SUB                                              ~72     !10, 1
        111        ADD                                              ~73     ~72, !9
        112        FETCH_DIM_R                                      ~74     !4, ~73
        113        ADD                                              ~75     ~74, 1
        114        SEND_VAL                                                 ~75
        115        ADD                                              ~76     !10, 1
        116        ADD                                              ~77     ~76, !9
        117        FETCH_DIM_R                                      ~78     !4, ~77
        118        SEND_VAL                                                 ~78
        119        DO_ICALL                                         $79     
        120        SEND_VAR                                                 $79
        121        SEND_VAR                                                 !2
        122        SEND_VAR                                                 !3
        123        DO_FCALL                                      0  $80     
        124        ASSIGN_DIM                                               !4, ~70
        125        OP_DATA                                                  $80
   22   126        PRE_INC                                                  !8
        127    >   ADD                                              ~82     !10, !9
        128        FETCH_DIM_R                                      ~83     !4, ~82
        129        INIT_FCALL                                               'mb_strlen'
        130        SEND_VAR                                                 !3
        131        DO_ICALL                                         $84     
        132        IS_NOT_EQUAL                                             $84, ~83
        133      > JMPNZ                                                    ~85, ->54
   29   134    >   SUB                                              ~86     !8, 1
        135        MUL                                              ~87     ~86, 2
        136        ADD                                              ~88     !10, ~87
        137      > RETURN                                                   ~88
   30   138*     > RETURN                                                   null

End of function edit_distance_onp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.22 ms | 1415 KiB | 21 Q