3v4l.org

run code in 300+ PHP versions simultaneously
<?php function similarity($w1,$w2) { //return cosine similarity of w1 and w2 using formula in the //definition here: http://en.wikipedia.org/wiki/Cosine_similarity //get numerator: $numerator = 0; for($i = 0, $l = count($w1); $i < $l; $i++) $numerator += $w1[$i]*$w2[$i]; //get abs(w1) and abs(w2) $abs_w1 = 0; $abs_w2 = 0; for($i = 0, $l = count($w1); $i < $l; $i++) { $abs_w1 += $w1[i]*$w1[i]; $abs_w2 += $w2[i]*$w2[i]; } $abs_w1 = sqrt($abs_w1); $abs_w2 = sqrt($abs_w2); //make denominator: $denominator = $abs_w1*$abs_w2; return $numerator/$denominator; } similarity([1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,88]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZEVrL
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'similarity'
          1        SEND_VAL                                                 <array>
          2        SEND_VAL                                                 <array>
          3        DO_FCALL                                      0          
          4      > RETURN                                                   1

Function similarity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 20
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 20
Branch analysis from position: 35
Branch analysis from position: 20
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
Branch analysis from position: 7
filename:       /in/ZEVrL
function name:  similarity
number of ops:  48
compiled vars:  !0 = $w1, !1 = $w2, !2 = $numerator, !3 = $i, !4 = $l, !5 = $abs_w1, !6 = $abs_w2, !7 = $denominator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        ASSIGN                                                   !2, 0
    8     3        ASSIGN                                                   !3, 0
          4        COUNT                                            ~10     !0
          5        ASSIGN                                                   !4, ~10
          6      > JMP                                                      ->12
          7    >   FETCH_DIM_R                                      ~12     !0, !3
          8        FETCH_DIM_R                                      ~13     !1, !3
          9        MUL                                              ~14     ~12, ~13
         10        ASSIGN_OP                                     1          !2, ~14
         11        PRE_INC                                                  !3
         12    >   IS_SMALLER                                               !3, !4
         13      > JMPNZ                                                    ~17, ->7
   11    14    >   ASSIGN                                                   !5, 0
         15        ASSIGN                                                   !6, 0
   12    16        ASSIGN                                                   !3, 0
         17        COUNT                                            ~21     !0
         18        ASSIGN                                                   !4, ~21
         19      > JMP                                                      ->33
   13    20    >   FETCH_CONSTANT                                   ~23     'i'
         21        FETCH_DIM_R                                      ~24     !0, ~23
         22        FETCH_CONSTANT                                   ~25     'i'
         23        FETCH_DIM_R                                      ~26     !0, ~25
         24        MUL                                              ~27     ~24, ~26
         25        ASSIGN_OP                                     1          !5, ~27
   14    26        FETCH_CONSTANT                                   ~29     'i'
         27        FETCH_DIM_R                                      ~30     !1, ~29
         28        FETCH_CONSTANT                                   ~31     'i'
         29        FETCH_DIM_R                                      ~32     !1, ~31
         30        MUL                                              ~33     ~30, ~32
         31        ASSIGN_OP                                     1          !6, ~33
   12    32        PRE_INC                                                  !3
         33    >   IS_SMALLER                                               !3, !4
         34      > JMPNZ                                                    ~36, ->20
   16    35    >   INIT_FCALL                                               'sqrt'
         36        SEND_VAR                                                 !5
         37        DO_ICALL                                         $37     
         38        ASSIGN                                                   !5, $37
   17    39        INIT_FCALL                                               'sqrt'
         40        SEND_VAR                                                 !6
         41        DO_ICALL                                         $39     
         42        ASSIGN                                                   !6, $39
   20    43        MUL                                              ~41     !5, !6
         44        ASSIGN                                                   !7, ~41
   22    45        DIV                                              ~43     !2, !7
         46      > RETURN                                                   ~43
   23    47*     > RETURN                                                   null

End of function similarity

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.88 ms | 1403 KiB | 16 Q