3v4l.org

run code in 500+ 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); });

Abusive script

This script was stopped while abusing our resources

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                              ~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
         29      > 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/hO1Yf
function name:  {closure:/in/hO1Yf:20}
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/hO1Yf
function name:  {closure:/in/hO1Yf:26}
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/hO1Yf
function name:  {closure:/in/hO1Yf:33}
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

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

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.83 ms | 1479 KiB | 23 Q