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 < 100; $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; } echo edit_distance_onp("qwerty","qwertyu"); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FtCb7
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'edit_distance_onp'
          1        SEND_VAL                                                 'qwerty'
          2        SEND_VAL                                                 'qwertyu'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   33     5      > 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/FtCb7
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 = 51, Position 2 = 46
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 53
Branch analysis from position: 133
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 56
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
2 jumps found. (Code = 44) Position 1 = 105, Position 2 = 82
Branch analysis from position: 105
2 jumps found. (Code = 44) Position 1 = 133, Position 2 = 53
Branch analysis from position: 133
Branch analysis from position: 53
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 105, Position 2 = 82
Branch analysis from position: 105
Branch analysis from position: 82
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 56
Branch analysis from position: 79
Branch analysis from position: 56
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 46
Branch analysis from position: 51
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/FtCb7
function name:  edit_distance_onp
number of ops:  138
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    >   IS_SMALLER                                               !11, 100
         50      > JMPNZ                                                    ~37, ->46
   22    51    >   ASSIGN                                                   !8, 0
         52      > JMP                                                      ->126
   23    53    >   MUL                                              ~39     !8, -1
         54        ASSIGN                                                   !7, ~39
         55      > JMP                                                      ->77
   24    56    >   ADD                                              ~41     !7, !9
         57        INIT_FCALL                                               'snake'
         58        SEND_VAR                                                 !7
         59        INIT_FCALL                                               'max'
         60        SUB                                              ~43     !7, 1
         61        ADD                                              ~44     ~43, !9
         62        FETCH_DIM_R                                      ~45     !4, ~44
         63        ADD                                              ~46     ~45, 1
         64        SEND_VAL                                                 ~46
         65        ADD                                              ~47     !7, 1
         66        ADD                                              ~48     ~47, !9
         67        FETCH_DIM_R                                      ~49     !4, ~48
         68        SEND_VAL                                                 ~49
         69        DO_ICALL                                         $50     
         70        SEND_VAR                                                 $50
         71        SEND_VAR                                                 !2
         72        SEND_VAR                                                 !3
         73        DO_FCALL                                      0  $51     
         74        ASSIGN_DIM                                               !4, ~41
         75        OP_DATA                                                  $51
   23    76        PRE_INC                                                  !7
         77    >   IS_SMALLER                                               !7, !10
         78      > JMPNZ                                                    ~53, ->56
   25    79    >   ADD                                              ~54     !10, !8
         80        ASSIGN                                                   !7, ~54
         81      > JMP                                                      ->103
   26    82    >   ADD                                              ~56     !7, !9
         83        INIT_FCALL                                               'snake'
         84        SEND_VAR                                                 !7
         85        INIT_FCALL                                               'max'
         86        SUB                                              ~58     !7, 1
         87        ADD                                              ~59     ~58, !9
         88        FETCH_DIM_R                                      ~60     !4, ~59
         89        ADD                                              ~61     ~60, 1
         90        SEND_VAL                                                 ~61
         91        ADD                                              ~62     !7, 1
         92        ADD                                              ~63     ~62, !9
         93        FETCH_DIM_R                                      ~64     !4, ~63
         94        SEND_VAL                                                 ~64
         95        DO_ICALL                                         $65     
         96        SEND_VAR                                                 $65
         97        SEND_VAR                                                 !2
         98        SEND_VAR                                                 !3
         99        DO_FCALL                                      0  $66     
        100        ASSIGN_DIM                                               !4, ~56
        101        OP_DATA                                                  $66
   25   102        PRE_DEC                                                  !7
        103    >   IS_SMALLER                                               !10, !7
        104      > JMPNZ                                                    ~68, ->82
   27   105    >   ADD                                              ~69     !10, !9
        106        INIT_FCALL                                               'snake'
        107        SEND_VAR                                                 !10
        108        INIT_FCALL                                               'max'
        109        SUB                                              ~71     !10, 1
        110        ADD                                              ~72     ~71, !9
        111        FETCH_DIM_R                                      ~73     !4, ~72
        112        ADD                                              ~74     ~73, 1
        113        SEND_VAL                                                 ~74
        114        ADD                                              ~75     !10, 1
        115        ADD                                              ~76     ~75, !9
        116        FETCH_DIM_R                                      ~77     !4, ~76
        117        SEND_VAL                                                 ~77
        118        DO_ICALL                                         $78     
        119        SEND_VAR                                                 $78
        120        SEND_VAR                                                 !2
        121        SEND_VAR                                                 !3
        122        DO_FCALL                                      0  $79     
        123        ASSIGN_DIM                                               !4, ~69
        124        OP_DATA                                                  $79
   22   125        PRE_INC                                                  !8
        126    >   ADD                                              ~81     !10, !9
        127        FETCH_DIM_R                                      ~82     !4, ~81
        128        INIT_FCALL                                               'mb_strlen'
        129        SEND_VAR                                                 !3
        130        DO_ICALL                                         $83     
        131        IS_NOT_EQUAL                                             $83, ~82
        132      > JMPNZ                                                    ~84, ->53
   30   133    >   SUB                                              ~85     !8, 1
        134        MUL                                              ~86     ~85, 2
        135        ADD                                              ~87     !10, ~86
        136      > RETURN                                                   ~87
   31   137*     > RETURN                                                   null

End of function edit_distance_onp

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.1 ms | 1414 KiB | 21 Q