3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Při číselných indexech je první kolize hashe v případě intervalu 1000 se vyhledává v položkách pole, kde kolize klíčů není. Zvětšíme-li hodnotu intervalu (např zmiňovaných 2000000, začneme vyhledávat i v klíčích s kolizí. */ define('INTERVAL', 1000); /* DJBX33A Hash function implemented in PHP */ function DJBX33A($key) { $hash = 5381; if (is_int($key)) { $key = pack("I*", $key); } for ($i = 0, $c = strlen($key); $i < $c; $i++) { $hash = (($hash << 5) + $hash) + ord($key[$i]); } return $hash; } $col = []; $f = false; $arr = []; for ($i = 0; $i < 2000000; $i++) { $arr[$i] = ['a' => 1+1]; $col[DJBX33A($i)] += 1; if(!$f && $col[DJBX33A($i)] > 1) { var_dump(array($i, DJBX33A($i))); $f = true; die(); } //if($i < INTERVAL) $deb[DJBX33A($i)] = $col[DJBX33A($i)]; } $start = microtime(true); for ($i = 0; $i < 1000000; $i++) { $arr[mt_rand(0, INTERVAL-1)]; } $time = microtime(true) - $start; $deb = $col; var_dump(count($deb)); arsort($deb); var_dump(array_slice($deb, 0, 15, true)); var_dump($time);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 9
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 44
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 44
Branch analysis from position: 55
Branch analysis from position: 44
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 24
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 35
Branch analysis from position: 25
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 9
Branch analysis from position: 38
Branch analysis from position: 9
Branch analysis from position: 24
filename:       /in/jUhjl
function name:  (null)
number of ops:  81
compiled vars:  !0 = $col, !1 = $f, !2 = $arr, !3 = $i, !4 = $start, !5 = $time, !6 = $deb
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'INTERVAL'
          2        SEND_VAL                                                 1000
          3        DO_ICALL                                                 
   28     4        ASSIGN                                                   !0, <array>
   29     5        ASSIGN                                                   !1, <false>
   30     6        ASSIGN                                                   !2, <array>
   31     7        ASSIGN                                                   !3, 0
          8      > JMP                                                      ->36
   32     9    >   ASSIGN_DIM                                               !2, !3
         10        OP_DATA                                                  <array>
   33    11        INIT_FCALL                                               'djbx33a'
         12        SEND_VAR                                                 !3
         13        DO_FCALL                                      0  $13     
         14        ASSIGN_DIM_OP                +=               1          !0, $13
         15        OP_DATA                                                  1
   34    16        BOOL_NOT                                         ~15     !1
         17      > JMPZ_EX                                          ~15     ~15, ->24
         18    >   INIT_FCALL                                               'djbx33a'
         19        SEND_VAR                                                 !3
         20        DO_FCALL                                      0  $16     
         21        FETCH_DIM_R                                      ~17     !0, $16
         22        IS_SMALLER                                       ~18     1, ~17
         23        BOOL                                             ~15     ~18
         24    > > JMPZ                                                     ~15, ->35
   35    25    >   INIT_FCALL                                               'var_dump'
         26        INIT_ARRAY                                       ~19     !3
         27        INIT_FCALL                                               'djbx33a'
         28        SEND_VAR                                                 !3
         29        DO_FCALL                                      0  $20     
         30        ADD_ARRAY_ELEMENT                                ~19     $20
         31        SEND_VAL                                                 ~19
         32        DO_ICALL                                                 
   36    33        ASSIGN                                                   !1, <true>
   37    34      > EXIT                                                     
   31    35    >   PRE_INC                                                  !3
         36    >   IS_SMALLER                                               !3, 2000000
         37      > JMPNZ                                                    ~24, ->9
   42    38    >   INIT_FCALL                                               'microtime'
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                         $25     
         41        ASSIGN                                                   !4, $25
   44    42        ASSIGN                                                   !3, 0
         43      > JMP                                                      ->53
   45    44    >   INIT_FCALL                                               'mt_rand'
         45        SEND_VAL                                                 0
         46        FETCH_CONSTANT                                   ~28     'INTERVAL'
         47        SUB                                              ~29     ~28, 1
         48        SEND_VAL                                                 ~29
         49        DO_ICALL                                         $30     
         50        FETCH_DIM_R                                      ~31     !2, $30
         51        FREE                                                     ~31
   44    52        PRE_INC                                                  !3
         53    >   IS_SMALLER                                               !3, 1000000
         54      > JMPNZ                                                    ~33, ->44
   48    55    >   INIT_FCALL                                               'microtime'
         56        SEND_VAL                                                 <true>
         57        DO_ICALL                                         $34     
         58        SUB                                              ~35     $34, !4
         59        ASSIGN                                                   !5, ~35
   50    60        ASSIGN                                                   !6, !0
   51    61        INIT_FCALL                                               'var_dump'
         62        COUNT                                            ~38     !6
         63        SEND_VAL                                                 ~38
         64        DO_ICALL                                                 
   52    65        INIT_FCALL                                               'arsort'
         66        SEND_REF                                                 !6
         67        DO_ICALL                                                 
   53    68        INIT_FCALL                                               'var_dump'
         69        INIT_FCALL                                               'array_slice'
         70        SEND_VAR                                                 !6
         71        SEND_VAL                                                 0
         72        SEND_VAL                                                 15
         73        SEND_VAL                                                 <true>
         74        DO_ICALL                                         $41     
         75        SEND_VAR                                                 $41
         76        DO_ICALL                                                 
   55    77        INIT_FCALL                                               'var_dump'
         78        SEND_VAR                                                 !5
         79        DO_ICALL                                                 
         80      > RETURN                                                   1

Function djbx33a:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 13
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 13
Branch analysis from position: 24
Branch analysis from position: 13
Branch analysis from position: 9
filename:       /in/jUhjl
function name:  DJBX33A
number of ops:  26
compiled vars:  !0 = $key, !1 = $hash, !2 = $i, !3 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN                                                   !1, 5381
   19     2        TYPE_CHECK                                   16          !0
          3      > JMPZ                                                     ~5, ->9
   20     4    >   INIT_FCALL                                               'pack'
          5        SEND_VAL                                                 'I%2A'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !0, $6
   22     9    >   ASSIGN                                                   !2, 0
         10        STRLEN                                           ~9      !0
         11        ASSIGN                                                   !3, ~9
         12      > JMP                                                      ->22
   23    13    >   SL                                               ~11     !1, 5
         14        ADD                                              ~12     ~11, !1
         15        INIT_FCALL                                               'ord'
         16        FETCH_DIM_R                                      ~13     !0, !2
         17        SEND_VAL                                                 ~13
         18        DO_ICALL                                         $14     
         19        ADD                                              ~15     ~12, $14
         20        ASSIGN                                                   !1, ~15
   22    21        PRE_INC                                                  !2
         22    >   IS_SMALLER                                               !2, !3
         23      > JMPNZ                                                    ~18, ->13
   25    24    > > RETURN                                                   !1
   26    25*     > RETURN                                                   null

End of function djbx33a

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.41 ms | 1406 KiB | 32 Q