3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = []; //$s = 123456; $s = 's6tbdfgj222dJGk'; $rs = str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 10); $numGen = function() { return rand(1, 9999999); }; $strGen = function() { global $rs; return substr(str_shuffle($rs), 0, rand(10, 100)); }; //$gen = $numGen; $gen = $strGen; foreach ([10000, 1000, 100, 10] as $c) { echo "N={$c}\n"; for ($i = 0; $i < $c; $i++) { $a[$i] = $gen(); // if ($a[$i] === $s) { $a[$i] = null; } // if ($i === 0) { $a[$i] = $s; } // if ($i === $c / 2) { $a[$i] = $s; } // if ($i === $c - 1) { $a[$i] = $s; } } $t = microtime(1); $e = in_array($s, $a); echo "in_array: ", microtime(1) - $t, PHP_EOL; $t = microtime(1); $a = array_flip($a); $e = isset($a[$s]); echo "flip+isset: ", microtime(1) - $t, PHP_EOL; $t = microtime(1); $a = array_flip($a); $e = @$a[$s] === null; echo "flip+null comparison: ", microtime(1) - $t, PHP_EOL; $t = microtime(1); $e = array_search($s, $a); echo "array_search: ", microtime(1) - $t, PHP_EOL; echo PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 98
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 98
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 = 42) Position 1 = 13
Branch analysis from position: 13
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: 98
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 98
filename:       /in/IhZ8F
function name:  (null)
number of ops:  100
compiled vars:  !0 = $a, !1 = $s, !2 = $rs, !3 = $numGen, !4 = $strGen, !5 = $gen, !6 = $c, !7 = $i, !8 = $t, !9 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 's6tbdfgj222dJGk'
    5     2        INIT_FCALL                                               'str_repeat'
          3        SEND_VAL                                                 '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
          4        SEND_VAL                                                 10
          5        DO_ICALL                                         $12     
          6        ASSIGN                                                   !2, $12
    6     7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIhZ8F%3A6%240'
          8        ASSIGN                                                   !3, ~14
    9     9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIhZ8F%3A9%241'
         10        ASSIGN                                                   !4, ~16
   14    11        ASSIGN                                                   !5, !4
   15    12      > FE_RESET_R                                       $19     <array>, ->98
         13    > > FE_FETCH_R                                               $19, !6, ->98
   16    14    >   ROPE_INIT                                     3  ~21     'N%3D'
         15        ROPE_ADD                                      1  ~21     ~21, !6
         16        ROPE_END                                      2  ~20     ~21, '%0A'
         17        ECHO                                                     ~20
   17    18        ASSIGN                                                   !7, 0
         19      > JMP                                                      ->25
   18    20    >   INIT_DYNAMIC_CALL                                        !5
         21        DO_FCALL                                      0  $25     
         22        ASSIGN_DIM                                               !0, !7
         23        OP_DATA                                                  $25
   17    24        PRE_INC                                                  !7
         25    >   IS_SMALLER                                               !7, !6
         26      > JMPNZ                                                    ~27, ->20
   24    27    >   INIT_FCALL                                               'microtime'
         28        SEND_VAL                                                 1
         29        DO_ICALL                                         $28     
         30        ASSIGN                                                   !8, $28
   25    31        INIT_FCALL                                               'in_array'
         32        SEND_VAR                                                 !1
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                         $30     
         35        ASSIGN                                                   !9, $30
   26    36        ECHO                                                     'in_array%3A+++++++++++++++'
         37        INIT_FCALL                                               'microtime'
         38        SEND_VAL                                                 1
         39        DO_ICALL                                         $32     
         40        SUB                                              ~33     $32, !8
         41        ECHO                                                     ~33
         42        ECHO                                                     '%0A'
   27    43        INIT_FCALL                                               'microtime'
         44        SEND_VAL                                                 1
         45        DO_ICALL                                         $34     
         46        ASSIGN                                                   !8, $34
   28    47        INIT_FCALL                                               'array_flip'
         48        SEND_VAR                                                 !0
         49        DO_ICALL                                         $36     
         50        ASSIGN                                                   !0, $36
   29    51        ISSET_ISEMPTY_DIM_OBJ                         0  ~38     !0, !1
         52        ASSIGN                                                   !9, ~38
   30    53        ECHO                                                     'flip%2Bisset%3A+++++++++++++'
         54        INIT_FCALL                                               'microtime'
         55        SEND_VAL                                                 1
         56        DO_ICALL                                         $40     
         57        SUB                                              ~41     $40, !8
         58        ECHO                                                     ~41
         59        ECHO                                                     '%0A'
   31    60        INIT_FCALL                                               'microtime'
         61        SEND_VAL                                                 1
         62        DO_ICALL                                         $42     
         63        ASSIGN                                                   !8, $42
   32    64        INIT_FCALL                                               'array_flip'
         65        SEND_VAR                                                 !0
         66        DO_ICALL                                         $44     
         67        ASSIGN                                                   !0, $44
   33    68        BEGIN_SILENCE                                    ~46     
         69        FETCH_DIM_R                                      ~47     !0, !1
         70        END_SILENCE                                              ~46
         71        TYPE_CHECK                                    2  ~48     ~47
         72        ASSIGN                                                   !9, ~48
   34    73        ECHO                                                     'flip%2Bnull+comparison%3A+++'
         74        INIT_FCALL                                               'microtime'
         75        SEND_VAL                                                 1
         76        DO_ICALL                                         $50     
         77        SUB                                              ~51     $50, !8
         78        ECHO                                                     ~51
         79        ECHO                                                     '%0A'
   35    80        INIT_FCALL                                               'microtime'
         81        SEND_VAL                                                 1
         82        DO_ICALL                                         $52     
         83        ASSIGN                                                   !8, $52
   36    84        INIT_FCALL                                               'array_search'
         85        SEND_VAR                                                 !1
         86        SEND_VAR                                                 !0
         87        DO_ICALL                                         $54     
         88        ASSIGN                                                   !9, $54
   37    89        ECHO                                                     'array_search%3A+++++++++++'
         90        INIT_FCALL                                               'microtime'
         91        SEND_VAL                                                 1
         92        DO_ICALL                                         $56     
         93        SUB                                              ~57     $56, !8
         94        ECHO                                                     ~57
         95        ECHO                                                     '%0A'
   38    96        ECHO                                                     '%0A'
   15    97      > JMP                                                      ->13
         98    >   FE_FREE                                                  $19
   39    99      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FIhZ8F%3A6%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IhZ8F
function name:  {closure}
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   INIT_FCALL                                               'rand'
          1        SEND_VAL                                                 1
          2        SEND_VAL                                                 9999999
          3        DO_ICALL                                         $0      
          4      > RETURN                                                   $0
    8     5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIhZ8F%3A6%240

Function %00%7Bclosure%7D%2Fin%2FIhZ8F%3A9%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IhZ8F
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $rs
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   BIND_GLOBAL                                              !0, 'rs'
   11     1        INIT_FCALL                                               'substr'
          2        INIT_FCALL                                               'str_shuffle'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        SEND_VAL                                                 0
          7        INIT_FCALL                                               'rand'
          8        SEND_VAL                                                 10
          9        SEND_VAL                                                 100
         10        DO_ICALL                                         $2      
         11        SEND_VAR                                                 $2
         12        DO_ICALL                                         $3      
         13      > RETURN                                                   $3
   12    14*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIhZ8F%3A9%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.36 ms | 1404 KiB | 29 Q