3v4l.org

run code in 300+ PHP versions simultaneously
<?php function returnTime(callable $function, int $repeat = 100) { $tests = []; for ($i = 0; $i < $repeat; ++$i) { $startTime = microtime(true); $function(); $endTime = microtime(true); $tests[] = $endTime - $startTime; } // Representing the average return 1000 * array_sum($tests) / $repeat; } $array = array_fill(0, 500000, 1); echo "Duration of array_slice() + key(): ", returnTime(function() use ($array) { $lastKey = key(array_slice($array, -1, 1, true)); }); echo PHP_EOL; echo "Duration of end() + key(): " , returnTime(function() use ($array){ end($array); $lastKey = key($array); }); echo PHP_EOL; echo "Duration of array_key_last(): " , returnTime(function() use ($array){ $lastKey = array_key_last($array); });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hO1Yf
function name:  (null)
number of ops:  30
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'array_fill'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 500000
          3        SEND_VAL                                                 1
          4        DO_ICALL                                         $1      
          5        ASSIGN                                                   !0, $1
   20     6        ECHO                                                     'Duration+of+array_slice%28%29+%2B+key%28%29%3A+'
          7        INIT_FCALL                                               'returntime'
          8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhO1Yf%3A20%240'
          9        BIND_LEXICAL                                             ~3, !0
   22    10        SEND_VAL                                                 ~3
         11        DO_FCALL                                      0  $4      
         12        ECHO                                                     $4
   24    13        ECHO                                                     '%0A'
   26    14        ECHO                                                     'Duration+of+end%28%29+%2B+key%28%29%3A+'
         15        INIT_FCALL                                               'returntime'
         16        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhO1Yf%3A26%241'
         17        BIND_LEXICAL                                             ~5, !0
   29    18        SEND_VAL                                                 ~5
         19        DO_FCALL                                      0  $6      
         20        ECHO                                                     $6
   31    21        ECHO                                                     '%0A'
   33    22        ECHO                                                     'Duration+of+array_key_last%28%29%3A+'
         23        INIT_FCALL                                               'returntime'
         24        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FhO1Yf%3A33%242'
         25        BIND_LEXICAL                                             ~7, !0
   35    26        SEND_VAL                                                 ~7
         27        DO_FCALL                                      0  $8      
         28        ECHO                                                     $8
         29      > RETURN                                                   1

Function returntime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
Branch analysis from position: 5
filename:       /in/hO1Yf
function name:  returnTime
number of ops:  28
compiled vars:  !0 = $function, !1 = $repeat, !2 = $tests, !3 = $i, !4 = $startTime, !5 = $endTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      100
    6     2        ASSIGN                                                   !2, <array>
    8     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->19
    9     5    >   INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !4, $8
   10     9        INIT_DYNAMIC_CALL                                        !0
         10        DO_FCALL                                      0          
   11    11        INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !5, $11
   12    15        SUB                                              ~14     !5, !4
         16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  ~14
    8    18        PRE_INC                                                  !3
         19    >   IS_SMALLER                                               !3, !1
         20      > JMPNZ                                                    ~16, ->5
   16    21    >   INIT_FCALL                                               'array_sum'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $17     
         24        MUL                                              ~18     $17, 1000
         25        DIV                                              ~19     ~18, !1
         26      > RETURN                                                   ~19
   17    27*     > RETURN                                                   null

End of function returntime

Function %00%7Bclosure%7D%2Fin%2FhO1Yf%3A20%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hO1Yf
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $array, !1 = $lastKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   BIND_STATIC                                              !0
   21     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                                         $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                         $3      
         10        ASSIGN                                                   !1, $3
   22    11      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhO1Yf%3A20%240

Function %00%7Bclosure%7D%2Fin%2FhO1Yf%3A26%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hO1Yf
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $array, !1 = $lastKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   BIND_STATIC                                              !0
   27     1        INIT_FCALL                                               'end'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                                 
   28     4        INIT_FCALL                                               'key'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
   29     8      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhO1Yf%3A26%241

Function %00%7Bclosure%7D%2Fin%2FhO1Yf%3A33%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hO1Yf
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $array, !1 = $lastKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   BIND_STATIC                                              !0
   34     1        INIT_FCALL                                               'array_key_last'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
   35     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FhO1Yf%3A33%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.16 ms | 1407 KiB | 30 Q