3v4l.org

run code in 300+ PHP versions simultaneously
<?php $benchFx = function (string $msg, \Closure $fx) { $times = []; for ($i = 0; $i < 10; $i++) { $t = microtime(true); $fx(); $t = microtime(true) - $t; $times[] = $t; } $bestTime = min($times); echo $msg . ': ' . round($bestTime * 1000, 2) . " ms\n"; }; $benchFx('append', function () { $arr = []; for ($i = 0; $i < 1_000; $i++) { $arr[] = 'x'; } }); $benchFx('array_push', function () { $arr = []; for ($i = 0; $i < 1_000; $i++) { array_push($arr, 'x'); } }); $benchFx('array_unshift', function () { $arr = []; for ($i = 0; $i < 1_000; $i++) { array_unshift($arr, 'x'); } });
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eFdHL
function name:  (null)
number of ops:  18
compiled vars:  !0 = $benchFx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          1        ASSIGN                                                   !0, ~1
   16     2        INIT_DYNAMIC_CALL                                        !0
          3        SEND_VAL_EX                                              'append'
          4        DECLARE_LAMBDA_FUNCTION                          ~3      [1]
   21     5        SEND_VAL_EX                                              ~3
   16     6        DO_FCALL                                      0          
   23     7        INIT_DYNAMIC_CALL                                        !0
          8        SEND_VAL_EX                                              'array_push'
          9        DECLARE_LAMBDA_FUNCTION                          ~5      [2]
   28    10        SEND_VAL_EX                                              ~5
   23    11        DO_FCALL                                      0          
   30    12        INIT_DYNAMIC_CALL                                        !0
         13        SEND_VAL_EX                                              'array_unshift'
         14        DECLARE_LAMBDA_FUNCTION                          ~7      [3]
   35    15        SEND_VAL_EX                                              ~7
   30    16        DO_FCALL                                      0          
   35    17      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
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/eFdHL
function name:  {closure}
number of ops:  35
compiled vars:  !0 = $msg, !1 = $fx, !2 = $times, !3 = $i, !4 = $t, !5 = $bestTime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->19
    6     5    >   INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !4, $8
    7     9        INIT_DYNAMIC_CALL                                        !1
         10        DO_FCALL                                      0          
    8    11        INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $11     
         14        SUB                                              ~12     $11, !4
         15        ASSIGN                                                   !4, ~12
    9    16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  !4
    5    18        PRE_INC                                                  !3
         19    >   IS_SMALLER                                               !3, 10
         20      > JMPNZ                                                    ~16, ->5
   12    21    >   INIT_FCALL                                               'min'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $17     
         24        ASSIGN                                                   !5, $17
   13    25        CONCAT                                           ~19     !0, '%3A+'
         26        INIT_FCALL                                               'round'
         27        MUL                                              ~20     !5, 1000
         28        SEND_VAL                                                 ~20
         29        SEND_VAL                                                 2
         30        DO_ICALL                                         $21     
         31        CONCAT                                           ~22     ~19, $21
         32        CONCAT                                           ~23     ~22, '+ms%0A'
         33        ECHO                                                     ~23
   14    34      > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 3
Branch analysis from position: 8
Branch analysis from position: 3
filename:       /in/eFdHL
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $arr, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   18     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->6
   19     3    >   ASSIGN_DIM                                               !0
          4        OP_DATA                                                  'x'
   18     5        PRE_INC                                                  !1
          6    >   IS_SMALLER                                               !1, 1000
          7      > JMPNZ                                                    ~6, ->3
   21     8    > > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 3
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 3
Branch analysis from position: 10
Branch analysis from position: 3
filename:       /in/eFdHL
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $arr, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, <array>
   25     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->8
   26     3    >   INIT_FCALL                                               'array_push'
          4        SEND_REF                                                 !0
          5        SEND_VAL                                                 'x'
          6        DO_ICALL                                                 
   25     7        PRE_INC                                                  !1
          8    >   IS_SMALLER                                               !1, 1000
          9      > JMPNZ                                                    ~6, ->3
   28    10    > > RETURN                                                   null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 3
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 3
Branch analysis from position: 10
Branch analysis from position: 3
filename:       /in/eFdHL
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $arr, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, <array>
   32     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->8
   33     3    >   INIT_FCALL                                               'array_unshift'
          4        SEND_REF                                                 !0
          5        SEND_VAL                                                 'x'
          6        DO_ICALL                                                 
   32     7        PRE_INC                                                  !1
          8    >   IS_SMALLER                                               !1, 1000
          9      > JMPNZ                                                    ~6, ->3
   35    10    > > RETURN                                                   null

End of Dynamic Function 3

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.03 ms | 1015 KiB | 18 Q