3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = []; for ($i = 0, $j = 100; $i < $j; ++$i) { $array[] = new DateTimeImmutable(); } function a($array) { $fn = function () use ($array) { foreach ($array as $item) { $x = $item instanceof DateTimeImmutable; } }; return $fn; } function b($array) { $fn = function () use (&$array) { foreach ($array as $item) { $x = $item instanceof DateTimeImmutable; } }; return $fn; } $t1 = microtime(true); for ($i = 0; $i < 100; ++$i) { a($array); } $t2 = microtime(true); for ($i = 0; $i < 100; ++$i) { b($array); } $t3 = microtime(true); echo (1000000 * ($t2 - $t1)) . "\n\n"; echo (1000000 * ($t3 - $t2)) . "\n\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 17
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 29
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 29
Branch analysis from position: 35
Branch analysis from position: 29
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 17
Branch analysis from position: 23
Branch analysis from position: 17
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 4
Branch analysis from position: 11
Branch analysis from position: 4
filename:       /in/bvNKI
function name:  (null)
number of ops:  48
compiled vars:  !0 = $array, !1 = $i, !2 = $j, !3 = $t1, !4 = $t2, !5 = $t3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, 0
          2        ASSIGN                                                   !2, 100
          3      > JMP                                                      ->9
    6     4    >   NEW                                              $10     'DateTimeImmutable'
          5        DO_FCALL                                      0          
          6        ASSIGN_DIM                                               !0
          7        OP_DATA                                                  $10
    5     8        PRE_INC                                                  !1
          9    >   IS_SMALLER                                               !1, !2
         10      > JMPNZ                                                    ~13, ->4
   26    11    >   INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $14     
         14        ASSIGN                                                   !3, $14
   27    15        ASSIGN                                                   !1, 0
         16      > JMP                                                      ->21
   28    17    >   INIT_FCALL                                               'a'
         18        SEND_VAR                                                 !0
         19        DO_FCALL                                      0          
   27    20        PRE_INC                                                  !1
         21    >   IS_SMALLER                                               !1, 100
         22      > JMPNZ                                                    ~19, ->17
   30    23    >   INIT_FCALL                                               'microtime'
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $20     
         26        ASSIGN                                                   !4, $20
   31    27        ASSIGN                                                   !1, 0
         28      > JMP                                                      ->33
   32    29    >   INIT_FCALL                                               'b'
         30        SEND_VAR                                                 !0
         31        DO_FCALL                                      0          
   31    32        PRE_INC                                                  !1
         33    >   IS_SMALLER                                               !1, 100
         34      > JMPNZ                                                    ~25, ->29
   34    35    >   INIT_FCALL                                               'microtime'
         36        SEND_VAL                                                 <true>
         37        DO_ICALL                                         $26     
         38        ASSIGN                                                   !5, $26
   36    39        SUB                                              ~28     !4, !3
         40        MUL                                              ~29     ~28, 1000000
         41        CONCAT                                           ~30     ~29, '%0A%0A'
         42        ECHO                                                     ~30
   37    43        SUB                                              ~31     !5, !4
         44        MUL                                              ~32     ~31, 1000000
         45        CONCAT                                           ~33     ~32, '%0A%0A'
         46        ECHO                                                     ~33
         47      > RETURN                                                   1

Function a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bvNKI
function name:  a
number of ops:  6
compiled vars:  !0 = $array, !1 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          2        BIND_LEXICAL                                             ~2, !0
          3        ASSIGN                                                   !1, ~2
   15     4      > RETURN                                                   !1
   16     5*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 6
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/bvNKI
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $array, !1 = $item, !2 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   BIND_STATIC                                              !0
   11     1      > FE_RESET_R                                       $3      !0, ->6
          2    > > FE_FETCH_R                                               $3, !1, ->6
   12     3    >   INSTANCEOF                                       ~4      !1, 'DateTimeImmutable'
          4        ASSIGN                                                   !2, ~4
   11     5      > JMP                                                      ->2
          6    >   FE_FREE                                                  $3
   14     7      > RETURN                                                   null

End of Dynamic Function 0

End of function a

Function b:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bvNKI
function name:  b
number of ops:  6
compiled vars:  !0 = $array, !1 = $fn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          2        BIND_LEXICAL                                             ~2, !0
          3        ASSIGN                                                   !1, ~2
   23     4      > RETURN                                                   !1
   24     5*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 6
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 6
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/bvNKI
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $array, !1 = $item, !2 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   BIND_STATIC                                              !0
   19     1      > FE_RESET_R                                       $3      !0, ->6
          2    > > FE_FETCH_R                                               $3, !1, ->6
   20     3    >   INSTANCEOF                                       ~4      !1, 'DateTimeImmutable'
          4        ASSIGN                                                   !2, ~4
   19     5      > JMP                                                      ->2
          6    >   FE_FREE                                                  $3
   22     7      > RETURN                                                   null

End of Dynamic Function 0

End of function b

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.71 ms | 1009 KiB | 16 Q