3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface BarInterface{} function getMemoryUsage($size){ static $unit=['b','kb','mb','gb','tb','pb']; return $size > 0 ? @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i] : 0 . ' byte'; } class Bar implements BarInterface { } class Foo { public function variadic(\BarInterface ...$bars){} public function iterated(array $bars){} } $bars = []; for ($i=0; $i<10000 ;$i++) { $bars[] = new \Bar(); } $foo = new Foo(); $items = \count($bars); //initial call to reduce overhead $foo->variadic(...[]); $foo->iterated([]); microtime(true); memory_get_usage(true); //benchmark start $mem_start = memory_get_usage(true); $start = new \DateTime(); $foo->variadic(...$bars); $mem_variadic = memory_get_usage(true); $variadic = new \DateTime(); $variadicDiff = $start->diff($variadic)->format('%f'); printf('%sms (variadic passed %d %s increase)', $variadicDiff, $items, getMemoryUsage($mem_variadic-$mem_start)); echo \PHP_EOL . '--------' . \PHP_EOL; $mem_start = memory_get_usage(true); $start = new \DateTime(); $foo->iterated($bars); $mem_iterated = memory_get_usage(true); $iterated = new \DateTime(); $iteratedDiff = $start->diff($iterated)->format('%f'); printf('%sms (iterated passed %d %s increase)', $iteratedDiff, $items, getMemoryUsage($mem_iterated-$mem_start)); echo \PHP_EOL . '--------' . \PHP_EOL; if ($variadicDiff > $iteratedDiff) { $loser = 'Variadic'; $diff = $variadicDiff - $iteratedDiff; $loss = $diff / $iteratedDiff; } else { $loser = 'Iterated'; $diff = $iteratedDiff - $variadicDiff; $loss = $diff / $variadicDiff; } printf('%s was slower by %.2f%% (%d ms)', $loser, $loss * 100, $diff);
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
2 jumps found. (Code = 43) Position 1 = 102, Position 2 = 108
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 113
Branch analysis from position: 113
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 108
1 jumps found. (Code = 62) Position 1 = -2
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/3hOfJ
function name:  (null)
number of ops:  121
compiled vars:  !0 = $bars, !1 = $i, !2 = $foo, !3 = $items, !4 = $mem_start, !5 = $start, !6 = $mem_variadic, !7 = $variadic, !8 = $variadicDiff, !9 = $mem_iterated, !10 = $iterated, !11 = $iteratedDiff, !12 = $loser, !13 = $diff, !14 = $loss
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'bar'
   21     1        ASSIGN                                                   !0, <array>
   22     2        ASSIGN                                                   !1, 0
          3      > JMP                                                      ->9
   23     4    >   NEW                                              $18     'Bar'
          5        DO_FCALL                                      0          
          6        ASSIGN_DIM                                               !0
          7        OP_DATA                                                  $18
   22     8        PRE_INC                                                  !1
          9    >   IS_SMALLER                                               !1, 10000
         10      > JMPNZ                                                    ~21, ->4
   25    11    >   NEW                                              $22     'Foo'
         12        DO_FCALL                                      0          
         13        ASSIGN                                                   !2, $22
   26    14        COUNT                                            ~25     !0
         15        ASSIGN                                                   !3, ~25
   28    16        INIT_METHOD_CALL                                         !2, 'variadic'
         17        SEND_UNPACK                                              <array>
         18        CHECK_UNDEF_ARGS                                         
         19        DO_FCALL                                      1          
   29    20        INIT_METHOD_CALL                                         !2, 'iterated'
         21        SEND_VAL_EX                                              <array>
         22        DO_FCALL                                      0          
   30    23        INIT_FCALL                                               'microtime'
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                                 
   31    26        INIT_FCALL                                               'memory_get_usage'
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                                 
   34    29        INIT_FCALL                                               'memory_get_usage'
         30        SEND_VAL                                                 <true>
         31        DO_ICALL                                         $31     
         32        ASSIGN                                                   !4, $31
   35    33        NEW                                              $33     'DateTime'
         34        DO_FCALL                                      0          
         35        ASSIGN                                                   !5, $33
   36    36        INIT_METHOD_CALL                                         !2, 'variadic'
         37        SEND_UNPACK                                              !0
         38        CHECK_UNDEF_ARGS                                         
         39        DO_FCALL                                      1          
   37    40        INIT_FCALL                                               'memory_get_usage'
         41        SEND_VAL                                                 <true>
         42        DO_ICALL                                         $37     
         43        ASSIGN                                                   !6, $37
   38    44        NEW                                              $39     'DateTime'
         45        DO_FCALL                                      0          
         46        ASSIGN                                                   !7, $39
   39    47        INIT_METHOD_CALL                                         !5, 'diff'
         48        SEND_VAR_EX                                              !7
         49        DO_FCALL                                      0  $42     
         50        INIT_METHOD_CALL                                         $42, 'format'
         51        SEND_VAL_EX                                              '%25f'
         52        DO_FCALL                                      0  $43     
         53        ASSIGN                                                   !8, $43
   40    54        INIT_FCALL                                               'printf'
         55        SEND_VAL                                                 '%25sms+%28variadic+passed+%25d+%25s+increase%29'
         56        SEND_VAR                                                 !8
         57        SEND_VAR                                                 !3
         58        INIT_FCALL                                               'getmemoryusage'
         59        SUB                                              ~45     !6, !4
         60        SEND_VAL                                                 ~45
         61        DO_FCALL                                      0  $46     
         62        SEND_VAR                                                 $46
         63        DO_ICALL                                                 
   41    64        ECHO                                                     '%0A--------%0A'
   43    65        INIT_FCALL                                               'memory_get_usage'
         66        SEND_VAL                                                 <true>
         67        DO_ICALL                                         $48     
         68        ASSIGN                                                   !4, $48
   44    69        NEW                                              $50     'DateTime'
         70        DO_FCALL                                      0          
         71        ASSIGN                                                   !5, $50
   45    72        INIT_METHOD_CALL                                         !2, 'iterated'
         73        SEND_VAR_EX                                              !0
         74        DO_FCALL                                      0          
   46    75        INIT_FCALL                                               'memory_get_usage'
         76        SEND_VAL                                                 <true>
         77        DO_ICALL                                         $54     
         78        ASSIGN                                                   !9, $54
   47    79        NEW                                              $56     'DateTime'
         80        DO_FCALL                                      0          
         81        ASSIGN                                                   !10, $56
   48    82        INIT_METHOD_CALL                                         !5, 'diff'
         83        SEND_VAR_EX                                              !10
         84        DO_FCALL                                      0  $59     
         85        INIT_METHOD_CALL                                         $59, 'format'
         86        SEND_VAL_EX                                              '%25f'
         87        DO_FCALL                                      0  $60     
         88        ASSIGN                                                   !11, $60
   49    89        INIT_FCALL                                               'printf'
         90        SEND_VAL                                                 '%25sms+%28iterated+passed+%25d+%25s+increase%29'
         91        SEND_VAR                                                 !11
         92        SEND_VAR                                                 !3
         93        INIT_FCALL                                               'getmemoryusage'
         94        SUB                                              ~62     !9, !4
         95        SEND_VAL                                                 ~62
         96        DO_FCALL                                      0  $63     
         97        SEND_VAR                                                 $63
         98        DO_ICALL                                                 
   50    99        ECHO                                                     '%0A--------%0A'
   52   100        IS_SMALLER                                               !11, !8
        101      > JMPZ                                                     ~65, ->108
   53   102    >   ASSIGN                                                   !12, 'Variadic'
   54   103        SUB                                              ~67     !8, !11
        104        ASSIGN                                                   !13, ~67
   55   105        DIV                                              ~69     !13, !11
        106        ASSIGN                                                   !14, ~69
   52   107      > JMP                                                      ->113
   57   108    >   ASSIGN                                                   !12, 'Iterated'
   58   109        SUB                                              ~72     !11, !8
        110        ASSIGN                                                   !13, ~72
   59   111        DIV                                              ~74     !13, !8
        112        ASSIGN                                                   !14, ~74
   61   113    >   INIT_FCALL                                               'printf'
        114        SEND_VAL                                                 '%25s+was+slower+by+%25.2f%25%25+%28%25d+ms%29'
        115        SEND_VAR                                                 !12
        116        MUL                                              ~76     !14, 100
        117        SEND_VAL                                                 ~76
        118        SEND_VAR                                                 !13
        119        DO_ICALL                                                 
        120      > RETURN                                                   1

Function getmemoryusage:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3hOfJ
function name:  getMemoryUsage
number of ops:  31
compiled vars:  !0 = $size, !1 = $unit, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        BIND_STATIC                                              !1
    7     2        IS_SMALLER                                               0, !0
          3      > JMPZ                                                     ~3, ->28
          4    >   BEGIN_SILENCE                                    ~4      
          5        INIT_FCALL                                               'round'
          6        INIT_FCALL                                               'pow'
          7        SEND_VAL                                                 1024
          8        INIT_FCALL                                               'floor'
          9        INIT_FCALL                                               'log'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 1024
         12        DO_ICALL                                         $5      
         13        SEND_VAR                                                 $5
         14        DO_ICALL                                         $6      
         15        ASSIGN                                           ~7      !2, $6
         16        SEND_VAL                                                 ~7
         17        DO_ICALL                                         $8      
         18        DIV                                              ~9      !0, $8
         19        SEND_VAL                                                 ~9
         20        SEND_VAL                                                 2
         21        DO_ICALL                                         $10     
         22        END_SILENCE                                              ~4
         23        CONCAT                                           ~11     $10, '+'
         24        FETCH_DIM_R                                      ~12     !1, !2
         25        CONCAT                                           ~13     ~11, ~12
         26        QM_ASSIGN                                        ~14     ~13
         27      > JMP                                                      ->29
         28    >   QM_ASSIGN                                        ~14     '0+byte'
         29    > > RETURN                                                   ~14
    8    30*     > RETURN                                                   null

End of function getmemoryusage

Class BarInterface: [no user functions]
Class Bar: [no user functions]
Class Foo:
Function variadic:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3hOfJ
function name:  variadic
number of ops:  2
compiled vars:  !0 = $bars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV_VARIADIC                                    !0      
          1      > RETURN                                                   null

End of function variadic

Function iterated:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3hOfJ
function name:  iterated
number of ops:  2
compiled vars:  !0 = $bars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1      > RETURN                                                   null

End of function iterated

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.78 ms | 1022 KiB | 22 Q