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*$w1; $abs_w2 += $w2*$w2; } $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/OXaW3
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 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 20
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 20
Branch analysis from position: 27
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/OXaW3
function name:  similarity
number of ops:  40
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                                                      ->25
   13    20    >   MUL                                              ~23     !0, !0
         21        ASSIGN_OP                                     1          !5, ~23
   14    22        MUL                                              ~25     !1, !1
         23        ASSIGN_OP                                     1          !6, ~25
   12    24        PRE_INC                                                  !3
         25    >   IS_SMALLER                                               !3, !4
         26      > JMPNZ                                                    ~28, ->20
   16    27    >   INIT_FCALL                                               'sqrt'
         28        SEND_VAR                                                 !5
         29        DO_ICALL                                         $29     
         30        ASSIGN                                                   !5, $29
   17    31        INIT_FCALL                                               'sqrt'
         32        SEND_VAR                                                 !6
         33        DO_ICALL                                         $31     
         34        ASSIGN                                                   !6, $31
   20    35        MUL                                              ~33     !5, !6
         36        ASSIGN                                                   !7, ~33
   22    37        DIV                                              ~35     !2, !7
         38      > RETURN                                                   ~35
   23    39*     > RETURN                                                   null

End of function similarity

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.75 ms | 1403 KiB | 16 Q