3v4l.org

run code in 500+ PHP versions simultaneously
<?php const ITERATIONS = 5000; interface Actor {} class InnocentBystander { public int $value; public Actor $actor; } class GoodActor implements Actor { private array $subclasses = array(); public function __get(string $subclass) { if (isset($this->subclasses[$subclass])) { return $this->subclasses[$subclass]; } $this->subclasses[$subclass] = new $subclass; $this->subclasses[$subclass]->actor = $this; return $this->subclasses[$subclass]; } } class BadActor implements Actor { public function __get(string $subclass) { $this->$subclass = new $subclass; $this->$subclass->actor = $this; return $this->$subclass; } } function time_it(Actor $instance, callable $callable):float { $start = microtime( true ); for ( $i = 0; $i < ITERATIONS; $i ++ ) { $callable($instance, $i); } $time = ( microtime( true ) - $start )*1000; printf( "Total execution time for %d iterations for %s = %f milliseconds\n" , ITERATIONS, get_class($instance), $time ); return $time; } function main() { $callable = function($actor, $number) { $actor->InnocentBystander->value = $number; }; $bad_timed = time_it( new BadActor,$callable ); $good_timed = time_it( new GoodActor,$callable ); $delta = $good_timed - $bad_timed; printf( "Total time difference for %d iterations = %f milliseconds\n" , ITERATIONS, $delta); printf( "Total time difference for 1 iteration = 1/%s millisecond\n" , number_format(ITERATIONS/$delta,0)); } main();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HAkhjW
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                                'ITERATIONS', 5000
   12     1        DECLARE_CLASS                                                'goodactor'
   25     2        DECLARE_CLASS                                                'badactor'
   72     3        INIT_FCALL                                                   'main'
          4        DO_FCALL                                          0          
          5      > RETURN                                                       1

Function time_it:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 8
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 8
Branch analysis from position: 16
Branch analysis from position: 8
filename:       /in/HAkhjW
function name:  time_it
number of ops:  34
compiled vars:  !0 = $instance, !1 = $callable, !2 = $start, !3 = $i, !4 = $time
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   36     2        INIT_FCALL                                                   'microtime'
          3        SEND_VAL                                                     <true>
          4        DO_ICALL                                             $5      
          5        ASSIGN                                                       !2, $5
   38     6        ASSIGN                                                       !3, 0
          7      > JMP                                                          ->13
   39     8    >   INIT_DYNAMIC_CALL                                            !1
          9        SEND_VAR_EX                                                  !0
         10        SEND_VAR_EX                                                  !3
         11        DO_FCALL                                          0          
   38    12        PRE_INC                                                      !3
         13    >   FETCH_CONSTANT                                       ~10     'ITERATIONS'
         14        IS_SMALLER                                                   !3, ~10
         15      > JMPNZ                                                        ~11, ->8
   42    16    >   INIT_FCALL                                                   'microtime'
         17        SEND_VAL                                                     <true>
         18        DO_ICALL                                             $12     
         19        SUB                                                  ~13     $12, !2
         20        MUL                                                  ~14     ~13, 1000
         21        ASSIGN                                                       !4, ~14
   44    22        INIT_FCALL                                                   'printf'
         23        SEND_VAL                                                     'Total+execution+time+for+%25d+iterations+for+%25s+%3D+%25f+milliseconds%0A'
   45    24        FETCH_CONSTANT                                       ~16     'ITERATIONS'
         25        SEND_VAL                                                     ~16
   46    26        GET_CLASS                                            ~17     !0
         27        SEND_VAL                                                     ~17
   47    28        SEND_VAR                                                     !4
   44    29        DO_ICALL                                                     
   49    30        VERIFY_RETURN_TYPE                                           !4
         31      > RETURN                                                       !4
   51    32*       VERIFY_RETURN_TYPE                                           
         33*     > RETURN                                                       null

End of function time_it

Function main:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HAkhjW
function name:  main
number of ops:  35
compiled vars:  !0 = $callable, !1 = $bad_timed, !2 = $good_timed, !3 = $delta
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   55     0  E >   DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          1        ASSIGN                                                       !0, ~4
   59     2        INIT_FCALL                                                   'time_it'
          3        NEW                                                  $6      'BadActor'
          4        DO_FCALL                                          0          
          5        SEND_VAR                                                     $6
          6        SEND_VAR                                                     !0
          7        DO_FCALL                                          0  $8      
          8        ASSIGN                                                       !1, $8
   60     9        INIT_FCALL                                                   'time_it'
         10        NEW                                                  $10     'GoodActor'
         11        DO_FCALL                                          0          
         12        SEND_VAR                                                     $10
         13        SEND_VAR                                                     !0
         14        DO_FCALL                                          0  $12     
         15        ASSIGN                                                       !2, $12
   62    16        SUB                                                  ~14     !2, !1
         17        ASSIGN                                                       !3, ~14
   64    18        INIT_FCALL                                                   'printf'
         19        SEND_VAL                                                     'Total+time+difference+for+%25d+iterations+%3D+%25f+milliseconds%0A'
   65    20        FETCH_CONSTANT                                       ~16     'ITERATIONS'
         21        SEND_VAL                                                     ~16
   66    22        SEND_VAR                                                     !3
   64    23        DO_ICALL                                                     
   68    24        INIT_FCALL                                                   'printf'
         25        SEND_VAL                                                     'Total+time+difference+for+1+iteration+%3D+1%2F%25s+millisecond%0A'
   69    26        INIT_FCALL                                                   'number_format'
         27        FETCH_CONSTANT                                       ~18     'ITERATIONS'
         28        DIV                                                  ~19     ~18, !3
         29        SEND_VAL                                                     ~19
         30        SEND_VAL                                                     0
         31        DO_ICALL                                             $20     
         32        SEND_VAR                                                     $20
   68    33        DO_ICALL                                                     
   70    34      > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HAkhjW
function name:  {closure:main():55}
number of ops:  6
compiled vars:  !0 = $actor, !1 = $number
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   55     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   56     2        FETCH_OBJ_W                                          $2      !0, 'InnocentBystander'
          3        ASSIGN_OBJ                                                   $2, 'value'
          4        OP_DATA                                                      !1
   57     5      > RETURN                                                       null

End of Dynamic Function 0

End of function main

Class Actor: [no user functions]
Class InnocentBystander: [no user functions]
Class GoodActor:
Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HAkhjW
function name:  __get
number of ops:  22
compiled vars:  !0 = $subclass
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
   16     1        FETCH_OBJ_IS                                         ~1      'subclasses'
          2        ISSET_ISEMPTY_DIM_OBJ                             0          ~1, !0
          3      > JMPZ                                                         ~2, ->7
   17     4    >   FETCH_OBJ_R                                          ~3      'subclasses'
          5        FETCH_DIM_R                                          ~4      ~3, !0
          6      > RETURN                                                       ~4
   19     7    >   FETCH_CLASS                                       0  $7      !0
          8        NEW                                                  $8      $7
          9        DO_FCALL                                          0          
         10        FETCH_OBJ_W                                          $5      'subclasses'
         11        ASSIGN_DIM                                                   $5, !0
         12        OP_DATA                                                      $8
   20    13        FETCH_THIS                                           ~13     
         14        FETCH_OBJ_W                                          $10     'subclasses'
         15        FETCH_DIM_W                                          $11     $10, !0
         16        ASSIGN_OBJ                                                   $11, 'actor'
         17        OP_DATA                                                      ~13
   21    18        FETCH_OBJ_R                                          ~14     'subclasses'
         19        FETCH_DIM_R                                          ~15     ~14, !0
         20      > RETURN                                                       ~15
   22    21*     > RETURN                                                       null

End of function __get

End of class GoodActor.

Class BadActor:
Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HAkhjW
function name:  __get
number of ops:  13
compiled vars:  !0 = $subclass
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
   28     1        FETCH_CLASS                                       0  $2      !0
          2        NEW                                                  $3      $2
          3        DO_FCALL                                          0          
          4        ASSIGN_OBJ                                                   !0
          5        OP_DATA                                                      $3
   29     6        FETCH_THIS                                           ~7      
          7        FETCH_OBJ_W                                          $5      !0
          8        ASSIGN_OBJ                                                   $5, 'actor'
          9        OP_DATA                                                      ~7
   30    10        FETCH_OBJ_R                                          ~8      !0
         11      > RETURN                                                       ~8
   31    12*     > RETURN                                                       null

End of function __get

End of class BadActor.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
276.02 ms | 1119 KiB | 20 Q