3v4l.org

run code in 300+ PHP versions simultaneously
<?php function returnTime(callable $function, int $repeat = 50) { $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, 200000, 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); }); echo PHP_EOL; echo "Duration of array_keys() + end(): " , returnTime(function() use ($array){ $keys = array_keys($array); $last = end($keys); }); echo PHP_EOL; echo "Duration of array_reverse() + key(): " , returnTime(function() use ($array){ $key = key(array_reverse($array)); }); echo PHP_EOL; echo "Duration of array_slice() + foreach(): " , returnTime(function() use ($array){ foreach (array_slice($array, -1, 1, true) as $key => $value); });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aguPF
function name:  (null)
number of ops:  54
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                                                 200000
          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                          ~3      [0]
          9        BIND_LEXICAL                                             ~3, !0
   22    10        SEND_VAL                                                 ~3
   20    11        DO_FCALL                                      0  $4      
   22    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                          ~5      [1]
         17        BIND_LEXICAL                                             ~5, !0
   29    18        SEND_VAL                                                 ~5
   26    19        DO_FCALL                                      0  $6      
   29    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                          ~7      [2]
         25        BIND_LEXICAL                                             ~7, !0
   35    26        SEND_VAL                                                 ~7
   33    27        DO_FCALL                                      0  $8      
   35    28        ECHO                                                     $8
   37    29        ECHO                                                     '%0A'
   39    30        ECHO                                                     'Duration+of+array_keys%28%29+%2B+end%28%29%3A+'
         31        INIT_FCALL                                               'returntime'
         32        DECLARE_LAMBDA_FUNCTION                          ~9      [3]
         33        BIND_LEXICAL                                             ~9, !0
   42    34        SEND_VAL                                                 ~9
   39    35        DO_FCALL                                      0  $10     
   42    36        ECHO                                                     $10
   44    37        ECHO                                                     '%0A'
   46    38        ECHO                                                     'Duration+of+array_reverse%28%29+%2B+key%28%29%3A+'
         39        INIT_FCALL                                               'returntime'
         40        DECLARE_LAMBDA_FUNCTION                          ~11     [4]
         41        BIND_LEXICAL                                             ~11, !0
   48    42        SEND_VAL                                                 ~11
   46    43        DO_FCALL                                      0  $12     
   48    44        ECHO                                                     $12
   50    45        ECHO                                                     '%0A'
   52    46        ECHO                                                     'Duration+of+array_slice%28%29+%2B+foreach%28%29%3A+'
         47        INIT_FCALL                                               'returntime'
         48        DECLARE_LAMBDA_FUNCTION                          ~13     [5]
         49        BIND_LEXICAL                                             ~13, !0
   54    50        SEND_VAL                                                 ~13
   52    51        DO_FCALL                                      0  $14     
   54    52        ECHO                                                     $14
         53      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aguPF
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 Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aguPF
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 Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aguPF
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 Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aguPF
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $array, !1 = $keys, !2 = $last
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   BIND_STATIC                                              !0
   40     1        INIT_FCALL                                               'array_keys'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !1, $3
   41     5        INIT_FCALL                                               'end'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !2, $5
   42     9      > RETURN                                                   null

End of Dynamic Function 3

Dynamic Function 4
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aguPF
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $array, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   BIND_STATIC                                              !0
   47     1        INIT_FCALL                                               'key'
          2        INIT_FCALL                                               'array_reverse'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
   48     8      > RETURN                                                   null

End of Dynamic Function 4

Dynamic Function 5
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/aguPF
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $array, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   BIND_STATIC                                              !0
   53     1        INIT_FCALL                                               'array_slice'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 -1
          4        SEND_VAL                                                 1
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $3      
          7      > FE_RESET_R                                       $4      $3, ->11
          8    > > FE_FETCH_R                                       ~5      $4, !1, ->11
          9    >   ASSIGN                                                   !2, ~5
         10      > JMP                                                      ->8
         11    >   FE_FREE                                                  $4
   54    12      > RETURN                                                   null

End of Dynamic Function 5

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/aguPF
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      50
    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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.86 ms | 1484 KiB | 28 Q