3v4l.org

run code in 300+ PHP versions simultaneously
<?php function run_test($name, $callback, $iterations) { $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $result = $callback(); } $stop = microtime(true); $delta = $stop - $start; echo "ran '$name' with result ", var_export($result, true), " in $delta msecs\n"; } class Foo { } class Bar { function setup() {} } $method1 = function($test) { return function () use ($test) { if (method_exists($test, 'setup')) { $test->setup(); } }; }; $method2 = function($test) { $func = method_exists($test, 'setup') ? function() use ($test) { $test->setup(); } : function () {}; return function () use ($func) { $func(); }; }; $method3 = function($test) { $test = method_exists($test, 'setup') ? [$test, 'setup'] : function () {}; return function () use ($test) { $test(); }; }; const ITERATIONS = 1000; run_test('foo1', $method1(new Foo()), ITERATIONS); run_test('bar1', $method1(new Bar()), ITERATIONS); run_test('foo2', $method2(new Foo()), ITERATIONS); run_test('bar2', $method2(new Bar()), ITERATIONS); run_test('foo3', $method3(new Foo()), ITERATIONS); run_test('bar3', $method3(new Bar()), ITERATIONS);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  (null)
number of ops:  74
compiled vars:  !0 = $method1, !1 = $method2, !2 = $method3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A25%240'
          1        ASSIGN                                                   !0, ~3
   34     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A34%242'
          3        ASSIGN                                                   !1, ~5
   44     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A44%246'
          5        ASSIGN                                                   !2, ~7
   54     6        DECLARE_CONST                                            'ITERATIONS', 1000
   56     7        INIT_FCALL                                               'run_test'
          8        SEND_VAL                                                 'foo1'
          9        INIT_DYNAMIC_CALL                                        !0
         10        NEW                                              $9      'Foo'
         11        DO_FCALL                                      0          
         12        SEND_VAR_NO_REF_EX                                       $9
         13        DO_FCALL                                      0  $11     
         14        SEND_VAR                                                 $11
         15        FETCH_CONSTANT                                   ~12     'ITERATIONS'
         16        SEND_VAL                                                 ~12
         17        DO_FCALL                                      0          
   57    18        INIT_FCALL                                               'run_test'
         19        SEND_VAL                                                 'bar1'
         20        INIT_DYNAMIC_CALL                                        !0
         21        NEW                                              $14     'Bar'
         22        DO_FCALL                                      0          
         23        SEND_VAR_NO_REF_EX                                       $14
         24        DO_FCALL                                      0  $16     
         25        SEND_VAR                                                 $16
         26        FETCH_CONSTANT                                   ~17     'ITERATIONS'
         27        SEND_VAL                                                 ~17
         28        DO_FCALL                                      0          
   59    29        INIT_FCALL                                               'run_test'
         30        SEND_VAL                                                 'foo2'
         31        INIT_DYNAMIC_CALL                                        !1
         32        NEW                                              $19     'Foo'
         33        DO_FCALL                                      0          
         34        SEND_VAR_NO_REF_EX                                       $19
         35        DO_FCALL                                      0  $21     
         36        SEND_VAR                                                 $21
         37        FETCH_CONSTANT                                   ~22     'ITERATIONS'
         38        SEND_VAL                                                 ~22
         39        DO_FCALL                                      0          
   60    40        INIT_FCALL                                               'run_test'
         41        SEND_VAL                                                 'bar2'
         42        INIT_DYNAMIC_CALL                                        !1
         43        NEW                                              $24     'Bar'
         44        DO_FCALL                                      0          
         45        SEND_VAR_NO_REF_EX                                       $24
         46        DO_FCALL                                      0  $26     
         47        SEND_VAR                                                 $26
         48        FETCH_CONSTANT                                   ~27     'ITERATIONS'
         49        SEND_VAL                                                 ~27
         50        DO_FCALL                                      0          
   62    51        INIT_FCALL                                               'run_test'
         52        SEND_VAL                                                 'foo3'
         53        INIT_DYNAMIC_CALL                                        !2
         54        NEW                                              $29     'Foo'
         55        DO_FCALL                                      0          
         56        SEND_VAR_NO_REF_EX                                       $29
         57        DO_FCALL                                      0  $31     
         58        SEND_VAR                                                 $31
         59        FETCH_CONSTANT                                   ~32     'ITERATIONS'
         60        SEND_VAL                                                 ~32
         61        DO_FCALL                                      0          
   63    62        INIT_FCALL                                               'run_test'
         63        SEND_VAL                                                 'bar3'
         64        INIT_DYNAMIC_CALL                                        !2
         65        NEW                                              $34     'Bar'
         66        DO_FCALL                                      0          
         67        SEND_VAR_NO_REF_EX                                       $34
         68        DO_FCALL                                      0  $36     
         69        SEND_VAR                                                 $36
         70        FETCH_CONSTANT                                   ~37     'ITERATIONS'
         71        SEND_VAL                                                 ~37
         72        DO_FCALL                                      0          
         73      > RETURN                                                   1

Function run_test:
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 = 15, Position 2 = 9
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 9
Branch analysis from position: 15
Branch analysis from position: 9
filename:       /in/8d4IA
function name:  run_test
number of ops:  35
compiled vars:  !0 = $name, !1 = $callback, !2 = $iterations, !3 = $start, !4 = $i, !5 = $result, !6 = $stop, !7 = $delta
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        INIT_FCALL                                               'microtime'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !3, $8
    6     7        ASSIGN                                                   !4, 0
          8      > JMP                                                      ->13
    7     9    >   INIT_DYNAMIC_CALL                                        !1
         10        DO_FCALL                                      0  $11     
         11        ASSIGN                                                   !5, $11
    6    12        PRE_INC                                                  !4
         13    >   IS_SMALLER                                               !4, !2
         14      > JMPNZ                                                    ~14, ->9
    9    15    >   INIT_FCALL                                               'microtime'
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $15     
         18        ASSIGN                                                   !6, $15
   11    19        SUB                                              ~17     !6, !3
         20        ASSIGN                                                   !7, ~17
   12    21        ROPE_INIT                                     3  ~20     'ran+%27'
         22        ROPE_ADD                                      1  ~20     ~20, !0
         23        ROPE_END                                      2  ~19     ~20, '%27+with+result+'
         24        ECHO                                                     ~19
         25        INIT_FCALL                                               'var_export'
         26        SEND_VAR                                                 !5
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $22     
         29        ECHO                                                     $22
   13    30        ROPE_INIT                                     3  ~24     '+in+'
         31        ROPE_ADD                                      1  ~24     ~24, !7
         32        ROPE_END                                      2  ~23     ~24, '+msecs%0A'
         33        ECHO                                                     ~23
   14    34      > RETURN                                                   null

End of function run_test

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A25%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A26%241'
          2        BIND_LEXICAL                                             ~1, !0
   30     3      > RETURN                                                   ~1
   31     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A25%240

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A26%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/8d4IA
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   BIND_STATIC                                              !0
   27     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->8
   28     6    >   INIT_METHOD_CALL                                         !0, 'setup'
          7        DO_FCALL                                      0          
   30     8    > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A26%241

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A34%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $test, !1 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $2      
          5      > JMPZ                                                     $2, ->10
   36     6    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A36%243'
          7        BIND_LEXICAL                                             ~3, !0
          8        QM_ASSIGN                                        ~4      ~3
          9      > JMP                                                      ->12
   37    10    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A37%244'
         11        QM_ASSIGN                                        ~4      ~5
   35    12    >   ASSIGN                                                   !1, ~4
   38    13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A38%245'
         14        BIND_LEXICAL                                             ~7, !1
   40    15      > RETURN                                                   ~7
   41    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A34%242

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A36%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   BIND_STATIC                                              !0
          1        INIT_METHOD_CALL                                         !0, 'setup'
          2        DO_FCALL                                      0          
          3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A36%243

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A37%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  {closure}
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A37%244

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A38%245:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $func
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   BIND_STATIC                                              !0
   39     1        INIT_DYNAMIC_CALL                                        !0
          2        DO_FCALL                                      0          
   40     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A38%245

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A44%246:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   45     1        INIT_FCALL                                               'method_exists'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'setup'
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->10
   46     6    >   INIT_ARRAY                                       ~2      !0
          7        ADD_ARRAY_ELEMENT                                ~2      'setup'
          8        QM_ASSIGN                                        ~3      ~2
          9      > JMP                                                      ->12
   47    10    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A47%247'
         11        QM_ASSIGN                                        ~3      ~4
   45    12    >   ASSIGN                                                   !0, ~3
   48    13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F8d4IA%3A48%248'
         14        BIND_LEXICAL                                             ~6, !0
   50    15      > RETURN                                                   ~6
   51    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A44%246

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A47%247:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  {closure}
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A47%247

Function %00%7Bclosure%7D%2Fin%2F8d4IA%3A48%248:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   BIND_STATIC                                              !0
   49     1        INIT_DYNAMIC_CALL                                        !0
          2        DO_FCALL                                      0          
   50     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8d4IA%3A48%248

Class Foo: [no user functions]
Class Bar:
Function setup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8d4IA
function name:  setup
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E > > RETURN                                                   null

End of function setup

End of class Bar.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.44 ms | 1419 KiB | 25 Q