3v4l.org

run code in 300+ PHP versions simultaneously
<?php $funcs = [ function ($array) { end($array); $key = key($array); reset($array); return $key; }, function ($array) { return count($array) - 1; }, function ($array) { return key(array_slice($array,-1,1,true)); }, function ($array) { $keys = array_keys($array); return end($keys); } ]; $test = ['a', 'b', 'c', 'd', 'e']; foreach ($funcs as $f) { $results = []; for ($i = 0; $i < 1000000; $i++) { $start_time = microtime(TRUE); $f($test); $end_time = microtime(TRUE); $results[] = $end_time - $start_time; } echo sprintf('%f.4', array_sum($results) / count($results)) . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 44
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 44
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 15
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 15
Branch analysis from position: 32
Branch analysis from position: 15
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/fkf2R
function name:  (null)
number of ops:  46
compiled vars:  !0 = $funcs, !1 = $test, !2 = $f, !3 = $results, !4 = $i, !5 = $start_time, !6 = $end_time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ffkf2R%3A4%240'
   10     1        INIT_ARRAY                                       ~8      ~7
   12     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ffkf2R%3A12%241'
   15     3        ADD_ARRAY_ELEMENT                                ~8      ~9
   17     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ffkf2R%3A17%242'
   20     5        ADD_ARRAY_ELEMENT                                ~8      ~10
   22     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ffkf2R%3A22%243'
   25     7        ADD_ARRAY_ELEMENT                                ~8      ~11
    3     8        ASSIGN                                                   !0, ~8
   28     9        ASSIGN                                                   !1, <array>
   30    10      > FE_RESET_R                                       $14     !0, ->44
         11    > > FE_FETCH_R                                               $14, !2, ->44
   31    12    >   ASSIGN                                                   !3, <array>
   32    13        ASSIGN                                                   !4, 0
         14      > JMP                                                      ->30
   33    15    >   INIT_FCALL                                               'microtime'
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $17     
         18        ASSIGN                                                   !5, $17
   35    19        INIT_DYNAMIC_CALL                                        !2
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0          
   37    22        INIT_FCALL                                               'microtime'
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $20     
         25        ASSIGN                                                   !6, $20
   39    26        SUB                                              ~23     !6, !5
         27        ASSIGN_DIM                                               !3
         28        OP_DATA                                                  ~23
   32    29        PRE_INC                                                  !4
         30    >   IS_SMALLER                                               !4, 1000000
         31      > JMPNZ                                                    ~25, ->15
   42    32    >   INIT_FCALL                                               'sprintf'
         33        SEND_VAL                                                 '%25f.4'
         34        INIT_FCALL                                               'array_sum'
         35        SEND_VAR                                                 !3
         36        DO_ICALL                                         $26     
         37        COUNT                                            ~27     !3
         38        DIV                                              ~28     $26, ~27
         39        SEND_VAL                                                 ~28
         40        DO_ICALL                                         $29     
         41        CONCAT                                           ~30     $29, '%0A'
         42        ECHO                                                     ~30
   30    43      > JMP                                                      ->11
         44    >   FE_FREE                                                  $14
   43    45      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Ffkf2R%3A4%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fkf2R
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $array, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'end'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                                 
    7     4        INIT_FCALL                                               'key'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
    8     8        INIT_FCALL                                               'reset'
          9        SEND_REF                                                 !0
         10        DO_ICALL                                                 
    9    11      > RETURN                                                   !1
   10    12*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ffkf2R%3A4%240

Function %00%7Bclosure%7D%2Fin%2Ffkf2R%3A12%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fkf2R
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        COUNT                                            ~1      !0
          2        SUB                                              ~2      ~1, 1
          3      > RETURN                                                   ~2
   15     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ffkf2R%3A12%241

Function %00%7Bclosure%7D%2Fin%2Ffkf2R%3A17%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fkf2R
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        INIT_FCALL                                               'key'
          2        INIT_FCALL                                               'array_slice'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 -1
          5        SEND_VAL                                                 1
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $1      
          8        SEND_VAR                                                 $1
          9        DO_ICALL                                         $2      
         10      > RETURN                                                   $2
   20    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ffkf2R%3A17%242

Function %00%7Bclosure%7D%2Fin%2Ffkf2R%3A22%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fkf2R
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $array, !1 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        INIT_FCALL                                               'array_keys'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
   24     5        INIT_FCALL                                               'end'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                         $4      
          8      > RETURN                                                   $4
   25     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ffkf2R%3A22%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.38 ms | 949 KiB | 30 Q