3v4l.org

run code in 300+ PHP versions simultaneously
<?php function prepare($num) { echo "preparing array with $num elements ... "; $array = array(); for ($i=0; $i<$num; $i++) { $array[uniqid('', true)] = true; } echo 'OK', PHP_EOL; return $array; } function test($num, $cycles, $tries) { echo "@cycles: ", $cycles, PHP_EOL; echo "@length: ", $num, PHP_EOL; echo "@tries: ", $tries, PHP_EOL; $array = prepare($num); $key = uniqid('', true); echo "array_key_exists: "; $times = array(); for ($j=0; $j<$tries; $j++) { $t = microtime(true); for($i = 0; $i < $cycles; $i++) { array_key_exists($key, $array); } $times[$j] = microtime(true) - $t; } printf('%0.4f second(s)'.PHP_EOL, array_sum($times)/$tries); echo "isset: "; $times = array(); for ($j=0; $j<$tries; $j++) { $t = microtime(true); for($i = 0; $i < $cycles; $i++) { isset($array[$key]); } $times[$j] = microtime(true) - $t; } printf('%0.4f second(s)'.PHP_EOL, array_sum($times)/$tries); } $cycles = 100000; $tries = 5; echo '----------------------', PHP_EOL; test(1000, $cycles, $tries); echo '----------------------', PHP_EOL; test(10000, $cycles, $tries); echo '----------------------', PHP_EOL; test(100000, $cycles, $tries); echo '----------------------', PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gQe30
function name:  (null)
number of ops:  26
compiled vars:  !0 = $cycles, !1 = $tries
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, 100000
   45     1        ASSIGN                                                   !1, 5
   47     2        ECHO                                                     '----------------------'
          3        ECHO                                                     '%0A'
   48     4        INIT_FCALL                                               'test'
          5        SEND_VAL                                                 1000
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0          
   49     9        ECHO                                                     '----------------------'
         10        ECHO                                                     '%0A'
   50    11        INIT_FCALL                                               'test'
         12        SEND_VAL                                                 10000
         13        SEND_VAR                                                 !0
         14        SEND_VAR                                                 !1
         15        DO_FCALL                                      0          
   51    16        ECHO                                                     '----------------------'
         17        ECHO                                                     '%0A'
   52    18        INIT_FCALL                                               'test'
         19        SEND_VAL                                                 100000
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !1
         22        DO_FCALL                                      0          
   53    23        ECHO                                                     '----------------------'
         24        ECHO                                                     '%0A'
         25      > RETURN                                                   1

Function prepare:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 8
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 8
Branch analysis from position: 17
Branch analysis from position: 8
filename:       /in/gQe30
function name:  prepare
number of ops:  21
compiled vars:  !0 = $num, !1 = $array, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ROPE_INIT                                     3  ~4      'preparing+array+with+'
          2        ROPE_ADD                                      1  ~4      ~4, !0
          3        ROPE_END                                      2  ~3      ~4, '+elements+...+'
          4        ECHO                                                     ~3
    5     5        ASSIGN                                                   !1, <array>
    6     6        ASSIGN                                                   !2, 0
          7      > JMP                                                      ->15
    7     8    >   INIT_FCALL                                               'uniqid'
          9        SEND_VAL                                                 ''
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $8      
         12        ASSIGN_DIM                                               !1, $8
         13        OP_DATA                                                  <true>
    6    14        PRE_INC                                                  !2
         15    >   IS_SMALLER                                               !2, !0
         16      > JMPNZ                                                    ~11, ->8
    9    17    >   ECHO                                                     'OK'
         18        ECHO                                                     '%0A'
   10    19      > RETURN                                                   !1
   11    20*     > RETURN                                                   null

End of function prepare

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 25
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 57
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 63
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 57
Branch analysis from position: 77
Branch analysis from position: 57
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 63
Branch analysis from position: 68
Branch analysis from position: 63
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 31
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 25
Branch analysis from position: 45
Branch analysis from position: 25
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 31
Branch analysis from position: 36
Branch analysis from position: 31
filename:       /in/gQe30
function name:  test
number of ops:  86
compiled vars:  !0 = $num, !1 = $cycles, !2 = $tries, !3 = $array, !4 = $key, !5 = $times, !6 = $j, !7 = $t, !8 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   14     3        ECHO                                                     '%40cycles%3A+'
          4        ECHO                                                     !1
          5        ECHO                                                     '%0A'
   15     6        ECHO                                                     '%40length%3A+'
          7        ECHO                                                     !0
          8        ECHO                                                     '%0A'
   16     9        ECHO                                                     '%40tries%3A+'
         10        ECHO                                                     !2
         11        ECHO                                                     '%0A'
   18    12        INIT_FCALL                                               'prepare'
         13        SEND_VAR                                                 !0
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !3, $9
   19    16        INIT_FCALL                                               'uniqid'
         17        SEND_VAL                                                 ''
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $11     
         20        ASSIGN                                                   !4, $11
   21    21        ECHO                                                     'array_key_exists%3A+'
   22    22        ASSIGN                                                   !5, <array>
   23    23        ASSIGN                                                   !6, 0
         24      > JMP                                                      ->43
   24    25    >   INIT_FCALL                                               'microtime'
         26        SEND_VAL                                                 <true>
         27        DO_ICALL                                         $15     
         28        ASSIGN                                                   !7, $15
   25    29        ASSIGN                                                   !8, 0
         30      > JMP                                                      ->34
   26    31    >   ARRAY_KEY_EXISTS                                 ~18     !4, !3
         32        FREE                                                     ~18
   25    33        PRE_INC                                                  !8
         34    >   IS_SMALLER                                               !8, !1
         35      > JMPNZ                                                    ~20, ->31
   28    36    >   INIT_FCALL                                               'microtime'
         37        SEND_VAL                                                 <true>
         38        DO_ICALL                                         $22     
         39        SUB                                              ~23     $22, !7
         40        ASSIGN_DIM                                               !5, !6
         41        OP_DATA                                                  ~23
   23    42        PRE_INC                                                  !6
         43    >   IS_SMALLER                                               !6, !2
         44      > JMPNZ                                                    ~25, ->25
   30    45    >   INIT_FCALL                                               'printf'
         46        SEND_VAL                                                 '%250.4f+second%28s%29%0A'
         47        INIT_FCALL                                               'array_sum'
         48        SEND_VAR                                                 !5
         49        DO_ICALL                                         $26     
         50        DIV                                              ~27     $26, !2
         51        SEND_VAL                                                 ~27
         52        DO_ICALL                                                 
   32    53        ECHO                                                     'isset%3A+'
   33    54        ASSIGN                                                   !5, <array>
   34    55        ASSIGN                                                   !6, 0
         56      > JMP                                                      ->75
   35    57    >   INIT_FCALL                                               'microtime'
         58        SEND_VAL                                                 <true>
         59        DO_ICALL                                         $31     
         60        ASSIGN                                                   !7, $31
   36    61        ASSIGN                                                   !8, 0
         62      > JMP                                                      ->66
   37    63    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~34     !3, !4
         64        FREE                                                     ~34
   36    65        PRE_INC                                                  !8
         66    >   IS_SMALLER                                               !8, !1
         67      > JMPNZ                                                    ~36, ->63
   39    68    >   INIT_FCALL                                               'microtime'
         69        SEND_VAL                                                 <true>
         70        DO_ICALL                                         $38     
         71        SUB                                              ~39     $38, !7
         72        ASSIGN_DIM                                               !5, !6
         73        OP_DATA                                                  ~39
   34    74        PRE_INC                                                  !6
         75    >   IS_SMALLER                                               !6, !2
         76      > JMPNZ                                                    ~41, ->57
   41    77    >   INIT_FCALL                                               'printf'
         78        SEND_VAL                                                 '%250.4f+second%28s%29%0A'
         79        INIT_FCALL                                               'array_sum'
         80        SEND_VAR                                                 !5
         81        DO_ICALL                                         $42     
         82        DIV                                              ~43     $42, !2
         83        SEND_VAL                                                 ~43
         84        DO_ICALL                                                 
   42    85      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.79 ms | 1461 KiB | 21 Q