3v4l.org

run code in 300+ PHP versions simultaneously
<?php $refObjectTime = []; $objectTime = []; $copyArrayTime = []; $refArrayTime = []; function avg($array) { return empty($array) ? 0 : (array_sum($array) / count($array)); } function fooRefObject(&$var) { $var->test = 'bar'; } function fooObject($var) { $var->test = 'bar'; } function fooCopyArray($var) { $var['test'] = 'bar'; } function fooRefArray(&$var) { $var['test'] = 'bar'; } for ($i=0; $i<10000; ++$i) { //Passing object through reference, explicitly $start = microtime(true); $data = new stdclass; fooRefObject($data); $refObjectTime[] = microtime(true) - $start; //Passing object through reference, implicitly $start = microtime(true); $data = new stdclass; fooObject($data); $objectTime[] = microtime(true) - $start; //Passing array through copy-on-write $start = microtime(true); $data = []; fooCopyArray($data); $copyArrayTime[] = microtime(true) - $start; //Passing array through reference $start = microtime(true); $data = []; fooRefArray($data); $refArrayTime[] = microtime(true) - $start; } //Results: echo 'Results:' . PHP_EOL; echo 'Minimums:' . PHP_EOL . ' - Object through reference, explicitly: ' . min($refObjectTime) . PHP_EOL . ' - Object through reference, implicitly: ' . min($objectTime) . PHP_EOL . ' - Array through copy-on-write: ' . min($copyArrayTime) . PHP_EOL . ' - Array through reference: ' . min($refArrayTime) . PHP_EOL; echo 'Maximums:' . PHP_EOL . ' - Object through reference, explicitly: ' . max($refObjectTime) . PHP_EOL . ' - Object through reference, implicitly: ' . max($objectTime) . PHP_EOL . ' - Array through copy-on-write: ' . max($copyArrayTime) . PHP_EOL . ' - Array through reference: ' . max($refArrayTime) . PHP_EOL; echo 'Avergages:' . PHP_EOL . ' - Object through reference, explicitly: ' . avg($refObjectTime) . PHP_EOL . ' - Object through reference, implicitly: ' . avg($objectTime) . PHP_EOL . ' - Array through copy-on-write: ' . avg($copyArrayTime) . PHP_EOL . ' - Array through reference: ' . avg($refArrayTime) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 6
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 6
Branch analysis from position: 69
Branch analysis from position: 6
filename:       /in/NqHlZ
function name:  (null)
number of ops:  143
compiled vars:  !0 = $refObjectTime, !1 = $objectTime, !2 = $copyArrayTime, !3 = $refArrayTime, !4 = $i, !5 = $start, !6 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN                                                   !1, <array>
    4     2        ASSIGN                                                   !2, <array>
    5     3        ASSIGN                                                   !3, <array>
   22     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->67
   25     6    >   INIT_FCALL                                               'microtime'
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $12     
          9        ASSIGN                                                   !5, $12
   26    10        NEW                                              $14     'stdclass'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !6, $14
   27    13        INIT_FCALL                                               'foorefobject'
         14        SEND_REF                                                 !6
         15        DO_FCALL                                      0          
   28    16        INIT_FCALL                                               'microtime'
         17        SEND_VAL                                                 <true>
         18        DO_ICALL                                         $19     
         19        SUB                                              ~20     $19, !5
         20        ASSIGN_DIM                                               !0
         21        OP_DATA                                                  ~20
   31    22        INIT_FCALL                                               'microtime'
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $21     
         25        ASSIGN                                                   !5, $21
   32    26        NEW                                              $23     'stdclass'
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !6, $23
   33    29        INIT_FCALL                                               'fooobject'
         30        SEND_VAR                                                 !6
         31        DO_FCALL                                      0          
   34    32        INIT_FCALL                                               'microtime'
         33        SEND_VAL                                                 <true>
         34        DO_ICALL                                         $28     
         35        SUB                                              ~29     $28, !5
         36        ASSIGN_DIM                                               !1
         37        OP_DATA                                                  ~29
   37    38        INIT_FCALL                                               'microtime'
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                         $30     
         41        ASSIGN                                                   !5, $30
   38    42        ASSIGN                                                   !6, <array>
   39    43        INIT_FCALL                                               'foocopyarray'
         44        SEND_VAR                                                 !6
         45        DO_FCALL                                      0          
   40    46        INIT_FCALL                                               'microtime'
         47        SEND_VAL                                                 <true>
         48        DO_ICALL                                         $35     
         49        SUB                                              ~36     $35, !5
         50        ASSIGN_DIM                                               !2
         51        OP_DATA                                                  ~36
   43    52        INIT_FCALL                                               'microtime'
         53        SEND_VAL                                                 <true>
         54        DO_ICALL                                         $37     
         55        ASSIGN                                                   !5, $37
   44    56        ASSIGN                                                   !6, <array>
   45    57        INIT_FCALL                                               'foorefarray'
         58        SEND_REF                                                 !6
         59        DO_FCALL                                      0          
   46    60        INIT_FCALL                                               'microtime'
         61        SEND_VAL                                                 <true>
         62        DO_ICALL                                         $42     
         63        SUB                                              ~43     $42, !5
         64        ASSIGN_DIM                                               !3
         65        OP_DATA                                                  ~43
   22    66        PRE_INC                                                  !4
         67    >   IS_SMALLER                                               !4, 10000
         68      > JMPNZ                                                    ~45, ->6
   50    69    >   ECHO                                                     'Results%3A%0A'
   52    70        INIT_FCALL                                               'min'
         71        SEND_VAR                                                 !0
         72        DO_ICALL                                         $46     
         73        CONCAT                                           ~47     'Minimums%3A%0A++++-+Object+through+reference%2C+explicitly%3A+', $46
         74        CONCAT                                           ~48     ~47, '%0A'
   53    75        CONCAT                                           ~49     ~48, '++++-+Object+through+reference%2C+implicitly%3A+'
         76        INIT_FCALL                                               'min'
         77        SEND_VAR                                                 !1
         78        DO_ICALL                                         $50     
         79        CONCAT                                           ~51     ~49, $50
         80        CONCAT                                           ~52     ~51, '%0A'
   54    81        CONCAT                                           ~53     ~52, '++++-+Array+through+copy-on-write%3A+'
         82        INIT_FCALL                                               'min'
         83        SEND_VAR                                                 !2
         84        DO_ICALL                                         $54     
         85        CONCAT                                           ~55     ~53, $54
         86        CONCAT                                           ~56     ~55, '%0A'
   55    87        CONCAT                                           ~57     ~56, '++++-+Array+through+reference%3A+'
         88        INIT_FCALL                                               'min'
         89        SEND_VAR                                                 !3
         90        DO_ICALL                                         $58     
         91        CONCAT                                           ~59     ~57, $58
         92        CONCAT                                           ~60     ~59, '%0A'
         93        ECHO                                                     ~60
   57    94        INIT_FCALL                                               'max'
         95        SEND_VAR                                                 !0
         96        DO_ICALL                                         $61     
         97        CONCAT                                           ~62     'Maximums%3A%0A++++-+Object+through+reference%2C+explicitly%3A+', $61
         98        CONCAT                                           ~63     ~62, '%0A'
   58    99        CONCAT                                           ~64     ~63, '++++-+Object+through+reference%2C+implicitly%3A+'
        100        INIT_FCALL                                               'max'
        101        SEND_VAR                                                 !1
        102        DO_ICALL                                         $65     
        103        CONCAT                                           ~66     ~64, $65
        104        CONCAT                                           ~67     ~66, '%0A'
   59   105        CONCAT                                           ~68     ~67, '++++-+Array+through+copy-on-write%3A+'
        106        INIT_FCALL                                               'max'
        107        SEND_VAR                                                 !2
        108        DO_ICALL                                         $69     
        109        CONCAT                                           ~70     ~68, $69
        110        CONCAT                                           ~71     ~70, '%0A'
   60   111        CONCAT                                           ~72     ~71, '++++-+Array+through+reference%3A+'
        112        INIT_FCALL                                               'max'
        113        SEND_VAR                                                 !3
        114        DO_ICALL                                         $73     
        115        CONCAT                                           ~74     ~72, $73
        116        CONCAT                                           ~75     ~74, '%0A'
        117        ECHO                                                     ~75
   62   118        INIT_FCALL                                               'avg'
        119        SEND_VAR                                                 !0
        120        DO_FCALL                                      0  $76     
        121        CONCAT                                           ~77     'Avergages%3A%0A++++-+Object+through+reference%2C+explicitly%3A+', $76
        122        CONCAT                                           ~78     ~77, '%0A'
   63   123        CONCAT                                           ~79     ~78, '++++-+Object+through+reference%2C+implicitly%3A+'
        124        INIT_FCALL                                               'avg'
        125        SEND_VAR                                                 !1
        126        DO_FCALL                                      0  $80     
        127        CONCAT                                           ~81     ~79, $80
        128        CONCAT                                           ~82     ~81, '%0A'
   64   129        CONCAT                                           ~83     ~82, '++++-+Array+through+copy-on-write%3A+'
        130        INIT_FCALL                                               'avg'
        131        SEND_VAR                                                 !2
        132        DO_FCALL                                      0  $84     
        133        CONCAT                                           ~85     ~83, $84
        134        CONCAT                                           ~86     ~85, '%0A'
   65   135        CONCAT                                           ~87     ~86, '++++-+Array+through+reference%3A+'
        136        INIT_FCALL                                               'avg'
        137        SEND_VAR                                                 !3
        138        DO_FCALL                                      0  $88     
        139        CONCAT                                           ~89     ~87, $88
        140        CONCAT                                           ~90     ~89, '%0A'
        141        ECHO                                                     ~90
        142      > RETURN                                                   1

Function avg:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NqHlZ
function name:  avg
number of ops:  13
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        ISSET_ISEMPTY_CV                                         !0
          2      > JMPZ                                                     ~1, ->5
          3    >   QM_ASSIGN                                        ~2      0
          4      > JMP                                                      ->11
          5    >   INIT_FCALL                                               'array_sum'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8        COUNT                                            ~4      !0
          9        DIV                                              ~5      $3, ~4
         10        QM_ASSIGN                                        ~2      ~5
         11    > > RETURN                                                   ~2
         12*     > RETURN                                                   null

End of function avg

Function foorefobject:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NqHlZ
function name:  fooRefObject
number of ops:  4
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        ASSIGN_OBJ                                               !0, 'test'
          2        OP_DATA                                                  'bar'
   11     3      > RETURN                                                   null

End of function foorefobject

Function fooobject:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NqHlZ
function name:  fooObject
number of ops:  4
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               !0, 'test'
          2        OP_DATA                                                  'bar'
   14     3      > RETURN                                                   null

End of function fooobject

Function foocopyarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NqHlZ
function name:  fooCopyArray
number of ops:  4
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        ASSIGN_DIM                                               !0, 'test'
          2        OP_DATA                                                  'bar'
   17     3      > RETURN                                                   null

End of function foocopyarray

Function foorefarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NqHlZ
function name:  fooRefArray
number of ops:  4
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        ASSIGN_DIM                                               !0, 'test'
          2        OP_DATA                                                  'bar'
   20     3      > RETURN                                                   null

End of function foorefarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.12 ms | 1024 KiB | 25 Q