3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 < 10000; $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; }
based on fkf2R
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 77) Position 1 = 11, Position 2 = 47
Branch analysis from position: 11
Jump found. (Code = 78) Position 1 = 12, Position 2 = 47
Branch analysis from position: 12
Jump found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Jump found. (Code = 44) Position 1 = 33, Position 2 = 15
Branch analysis from position: 33
Jump found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 15
Jump found. (Code = 44) Position 1 = 33, Position 2 = 15
Branch analysis from position: 33
Branch analysis from position: 15
Branch analysis from position: 47
Jump found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/8j0ql
function name:  (null)
number of ops:  49
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%2F8j0ql0x7f7383c6508f'
  10     1        INIT_ARRAY                                       ~8      ~7
  12     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8j0ql0x7f7383c650d5'
  15     3        ADD_ARRAY_ELEMENT                                ~8      ~9
  17     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8j0ql0x7f7383c6512c'
  20     5        ADD_ARRAY_ELEMENT                                ~8      ~10
  22     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8j0ql0x7f7383c6518f'
  25     7        ADD_ARRAY_ELEMENT                                ~8      ~11
         8        ASSIGN                                                   !0, ~8
  28     9        ASSIGN                                                   !1, <array>
  30    10      > FE_RESET_R                                       $14     !0, ->47
        11    > > FE_FETCH_R                                               $14, !2, ->47
  31    12    >   ASSIGN                                                   !3, <array>
  32    13        ASSIGN                                                   !4, 0
        14      > JMP                                                      ->31
  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        POST_INC                                         ~24     !4
        30        FREE                                                     ~24
        31    >   IS_SMALLER                                       ~25     !4, 10000
        32      > JMPNZ                                                    ~25, ->15
  42    33    >   INIT_FCALL                                               'sprintf'
        34        SEND_VAL                                                 '%25f.4'
        35        INIT_FCALL                                               'array_sum'
        36        SEND_VAR                                                 !3
        37        DO_ICALL                                         $26     
        38        INIT_FCALL                                               'count'
        39        SEND_VAR                                                 !3
        40        DO_ICALL                                         $27     
        41        DIV                                              ~28     $26, $27
        42        SEND_VAL                                                 ~28
        43        DO_ICALL                                         $29     
        44        CONCAT                                           ~30     $29, '%0A'
        45        ECHO                                                     ~30
        46      > JMP                                                      ->11
        47    >   FE_FREE                                                  $14
  43    48      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F8j0ql0x7f7383c6508f:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/8j0ql
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%2F8j0ql0x7f7383c6508f

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

End of function %00%7Bclosure%7D%2Fin%2F8j0ql0x7f7383c650d5

Function %00%7Bclosure%7D%2Fin%2F8j0ql0x7f7383c6512c:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/8j0ql
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%2F8j0ql0x7f7383c6512c

Function %00%7Bclosure%7D%2Fin%2F8j0ql0x7f7383c6518f:
Finding entry points
Branch analysis from position: 0
Jump found. (Code = 62) Position 1 = -2
filename:       /in/8j0ql
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%2F8j0ql0x7f7383c6518f

Generated using Vulcan Logic Dumper, using php 7.3.0