3v4l.org

run code in 300+ PHP versions simultaneously
<?php $PHORUM = array( "OBJ" => new ArrayObject() ); for ($x = 0; $x < 100; $x++) { if ($x % 3 == 0) { $PHORUM[$x] = "XXXXXXXXXXX"; } elseif ($x % 5 == 0) { $PHORUM[$x] = array( "x" => array( "x" => array( "x" => array( "x" => "foo" ) ) ) ); } else { $PHORUM[$x] = rand(1,100); } } function global_copy_from() { global $PHORUM; $foo = $PHORUM[0]; } function GLOBALS_copy_from() { $PHORUM = $GLOBALS["PHORUM"]; $foo = $PHORUM[0]; } $use_copy_from = function() use ($PHORUM) { $foo = $PHORUM[0]; }; function global_check() { global $PHORUM; if ($PHORUM[0] > 1) {} } function GLOBALS_check() { $PHORUM = $GLOBALS["PHORUM"]; if ($PHORUM[0] > 1) {} } $use_check = function() use ($PHORUM) { if ($PHORUM[0] > 1) {} }; function global_change($i) { global $PHORUM; $PHORUM[0] = $i; } function GLOBALS_change($i) { $GLOBALS["PHORUM"][0] = $i; } $use_change = function($i) use (&$PHORUM) { $PHORUM[0] = $i; }; foreach (array("copy_from", "check", "change") as $z) { echo "$z:\n"; foreach (array("global", "GLOBALS", "use") as $x) { $runs = array(); $func = $x."_".$z; if (isset($$func)) { $callable = $$func; if (is_callable($callable)) { $func = $callable; } } for ($y = 0; $y < 31; $y++) { $time_start = microtime(true); for ($i=0; $i < 100; ++$i) { $func($i); } $time_end = microtime(true); $runs[] = round(($time_end - $time_start)*1000000, 3); } sort($runs); $runs = array_slice($runs, floor(count($runs) * 0.05), -1 * (floor(count($runs) * 0.05))); $avg = round((array_sum($runs)/count($runs)), 3); $low = reset($runs); $high = end($runs); $median = $runs[ceil(count($runs)/2)+1]; echo " $x:\n"; echo " avg: ".$avg."µs\n"; echo " median: ".$median."µs\n\n"; } echo "\n"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 6
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 37, Position 2 = 145
Branch analysis from position: 37
2 jumps found. (Code = 78) Position 1 = 38, Position 2 = 145
Branch analysis from position: 38
2 jumps found. (Code = 77) Position 1 = 42, Position 2 = 142
Branch analysis from position: 42
2 jumps found. (Code = 78) Position 1 = 43, Position 2 = 142
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 56
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 56
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 83
Branch analysis from position: 83
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 58
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 64
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 58
Branch analysis from position: 85
Branch analysis from position: 58
Branch analysis from position: 64
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 64
Branch analysis from position: 70
Branch analysis from position: 64
Branch analysis from position: 56
Branch analysis from position: 56
Branch analysis from position: 142
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 142
Branch analysis from position: 145
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 145
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 6
Branch analysis from position: 27
Branch analysis from position: 6
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 6
Branch analysis from position: 27
Branch analysis from position: 6
filename:       /in/9d9mu
function name:  (null)
number of ops:  147
compiled vars:  !0 = $PHORUM, !1 = $x, !2 = $use_copy_from, !3 = $use_check, !4 = $use_change, !5 = $z, !6 = $runs, !7 = $func, !8 = $callable, !9 = $y, !10 = $time_start, !11 = $i, !12 = $time_end, !13 = $avg, !14 = $low, !15 = $high, !16 = $median
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   NEW                                              $17     'ArrayObject'
          1        DO_FCALL                                      0          
          2        INIT_ARRAY                                       ~19     $17, 'OBJ'
    3     3        ASSIGN                                                   !0, ~19
    7     4        ASSIGN                                                   !1, 0
          5      > JMP                                                      ->25
    8     6    >   MOD                                              ~22     !1, 3
          7        IS_EQUAL                                                 ~22, 0
          8      > JMPZ                                                     ~23, ->12
    9     9    >   ASSIGN_DIM                                               !0, !1
         10        OP_DATA                                                  'XXXXXXXXXXX'
    8    11      > JMP                                                      ->24
   10    12    >   MOD                                              ~25     !1, 5
         13        IS_EQUAL                                                 ~25, 0
         14      > JMPZ                                                     ~26, ->18
   11    15    >   ASSIGN_DIM                                               !0, !1
   15    16        OP_DATA                                                  <array>
   10    17      > JMP                                                      ->24
   21    18    >   INIT_FCALL                                               'rand'
         19        SEND_VAL                                                 1
         20        SEND_VAL                                                 100
         21        DO_ICALL                                         $29     
         22        ASSIGN_DIM                                               !0, !1
         23        OP_DATA                                                  $29
    7    24    >   PRE_INC                                                  !1
         25    >   IS_SMALLER                                               !1, 100
         26      > JMPNZ                                                    ~31, ->6
   27    27    >   DECLARE_LAMBDA_FUNCTION                          ~32     [0]
         28        BIND_LEXICAL                                             ~32, !0
         29        ASSIGN                                                   !2, ~32
   31    30        DECLARE_LAMBDA_FUNCTION                          ~34     [1]
         31        BIND_LEXICAL                                             ~34, !0
         32        ASSIGN                                                   !3, ~34
   35    33        DECLARE_LAMBDA_FUNCTION                          ~36     [2]
         34        BIND_LEXICAL                                             ~36, !0
         35        ASSIGN                                                   !4, ~36
   39    36      > FE_RESET_R                                       $38     <array>, ->145
         37    > > FE_FETCH_R                                               $38, !5, ->145
   40    38    >   NOP                                                      
         39        FAST_CONCAT                                      ~39     !5, '%3A%0A'
         40        ECHO                                                     ~39
   41    41      > FE_RESET_R                                       $40     <array>, ->142
         42    > > FE_FETCH_R                                               $40, !1, ->142
   42    43    >   ASSIGN                                                   !6, <array>
   43    44        CONCAT                                           ~42     !1, '_'
         45        CONCAT                                           ~43     ~42, !5
         46        ASSIGN                                                   !7, ~43
   44    47        ISSET_ISEMPTY_VAR                             4          !7
         48      > JMPZ                                                     ~45, ->56
   45    49    >   FETCH_R                      local               ~46     !7
         50        ASSIGN                                                   !8, ~46
   46    51        INIT_FCALL                                               'is_callable'
         52        SEND_VAR                                                 !8
         53        DO_ICALL                                         $48     
         54      > JMPZ                                                     $48, ->56
   47    55    >   ASSIGN                                                   !7, !8
   50    56    >   ASSIGN                                                   !9, 0
         57      > JMP                                                      ->83
   51    58    >   INIT_FCALL                                               'microtime'
         59        SEND_VAL                                                 <true>
         60        DO_ICALL                                         $51     
         61        ASSIGN                                                   !10, $51
   52    62        ASSIGN                                                   !11, 0
         63      > JMP                                                      ->68
   53    64    >   INIT_DYNAMIC_CALL                                        !7
         65        SEND_VAR_EX                                              !11
         66        DO_FCALL                                      0          
   52    67        PRE_INC                                                  !11
         68    >   IS_SMALLER                                               !11, 100
         69      > JMPNZ                                                    ~56, ->64
   55    70    >   INIT_FCALL                                               'microtime'
         71        SEND_VAL                                                 <true>
         72        DO_ICALL                                         $57     
         73        ASSIGN                                                   !12, $57
   56    74        INIT_FCALL                                               'round'
         75        SUB                                              ~60     !12, !10
         76        MUL                                              ~61     ~60, 1000000
         77        SEND_VAL                                                 ~61
         78        SEND_VAL                                                 3
         79        DO_ICALL                                         $62     
         80        ASSIGN_DIM                                               !6
         81        OP_DATA                                                  $62
   50    82        PRE_INC                                                  !9
         83    >   IS_SMALLER                                               !9, 31
         84      > JMPNZ                                                    ~64, ->58
   58    85    >   INIT_FCALL                                               'sort'
         86        SEND_REF                                                 !6
         87        DO_ICALL                                                 
   59    88        INIT_FCALL                                               'array_slice'
         89        SEND_VAR                                                 !6
         90        INIT_FCALL                                               'floor'
         91        COUNT                                            ~66     !6
         92        MUL                                              ~67     ~66, 0.05
         93        SEND_VAL                                                 ~67
         94        DO_ICALL                                         $68     
         95        SEND_VAR                                                 $68
         96        INIT_FCALL                                               'floor'
         97        COUNT                                            ~69     !6
         98        MUL                                              ~70     ~69, 0.05
         99        SEND_VAL                                                 ~70
        100        DO_ICALL                                         $71     
        101        MUL                                              ~72     $71, -1
        102        SEND_VAL                                                 ~72
        103        DO_ICALL                                         $73     
        104        ASSIGN                                                   !6, $73
   60   105        INIT_FCALL                                               'round'
        106        INIT_FCALL                                               'array_sum'
        107        SEND_VAR                                                 !6
        108        DO_ICALL                                         $75     
        109        COUNT                                            ~76     !6
        110        DIV                                              ~77     $75, ~76
        111        SEND_VAL                                                 ~77
        112        SEND_VAL                                                 3
        113        DO_ICALL                                         $78     
        114        ASSIGN                                                   !13, $78
   61   115        INIT_FCALL                                               'reset'
        116        SEND_REF                                                 !6
        117        DO_ICALL                                         $80     
        118        ASSIGN                                                   !14, $80
   62   119        INIT_FCALL                                               'end'
        120        SEND_REF                                                 !6
        121        DO_ICALL                                         $82     
        122        ASSIGN                                                   !15, $82
   63   123        INIT_FCALL                                               'ceil'
        124        COUNT                                            ~84     !6
        125        DIV                                              ~85     ~84, 2
        126        SEND_VAL                                                 ~85
        127        DO_ICALL                                         $86     
        128        ADD                                              ~87     $86, 1
        129        FETCH_DIM_R                                      ~88     !6, ~87
        130        ASSIGN                                                   !16, ~88
   64   131        ROPE_INIT                                     3  ~91     '++'
        132        ROPE_ADD                                      1  ~91     ~91, !1
        133        ROPE_END                                      2  ~90     ~91, '%3A%0A'
        134        ECHO                                                     ~90
   65   135        CONCAT                                           ~93     '+++++avg%3A+', !13
        136        CONCAT                                           ~94     ~93, '%C2%B5s%0A'
        137        ECHO                                                     ~94
   66   138        CONCAT                                           ~95     '++median%3A+', !16
        139        CONCAT                                           ~96     ~95, '%C2%B5s%0A%0A'
        140        ECHO                                                     ~96
   41   141      > JMP                                                      ->42
        142    >   FE_FREE                                                  $40
   68   143        ECHO                                                     '%0A'
   39   144      > JMP                                                      ->37
        145    >   FE_FREE                                                  $38
   69   146      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9d9mu
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $PHORUM, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   BIND_STATIC                                              !0
          1        FETCH_DIM_R                                      ~2      !0, 0
          2        ASSIGN                                                   !1, ~2
          3      > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 4
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
filename:       /in/9d9mu
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $PHORUM
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   BIND_STATIC                                              !0
          1        FETCH_DIM_R                                      ~1      !0, 0
          2        IS_SMALLER                                               1, ~1
          3      > JMPZ                                                     ~2, ->4
          4    > > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9d9mu
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $i, !1 = $PHORUM
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        ASSIGN_DIM                                               !1, 0
          3        OP_DATA                                                  !0
          4      > RETURN                                                   null

End of Dynamic Function 2

Function global_copy_from:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9d9mu
function name:  global_copy_from
number of ops:  4
compiled vars:  !0 = $PHORUM, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   BIND_GLOBAL                                              !0, 'PHORUM'
          1        FETCH_DIM_R                                      ~2      !0, 0
          2        ASSIGN                                                   !1, ~2
          3      > RETURN                                                   null

End of function global_copy_from

Function globals_copy_from:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9d9mu
function name:  GLOBALS_copy_from
number of ops:  5
compiled vars:  !0 = $PHORUM, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   FETCH_R                      global              ~2      'PHORUM'
          1        ASSIGN                                                   !0, ~2
          2        FETCH_DIM_R                                      ~4      !0, 0
          3        ASSIGN                                                   !1, ~4
          4      > RETURN                                                   null

End of function globals_copy_from

Function global_check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 4
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
filename:       /in/9d9mu
function name:  global_check
number of ops:  5
compiled vars:  !0 = $PHORUM
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   BIND_GLOBAL                                              !0, 'PHORUM'
          1        FETCH_DIM_R                                      ~1      !0, 0
          2        IS_SMALLER                                               1, ~1
          3      > JMPZ                                                     ~2, ->4
          4    > > RETURN                                                   null

End of function global_check

Function globals_check:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 5
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/9d9mu
function name:  GLOBALS_check
number of ops:  6
compiled vars:  !0 = $PHORUM
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   FETCH_R                      global              ~1      'PHORUM'
          1        ASSIGN                                                   !0, ~1
          2        FETCH_DIM_R                                      ~3      !0, 0
          3        IS_SMALLER                                               1, ~3
          4      > JMPZ                                                     ~4, ->5
          5    > > RETURN                                                   null

End of function globals_check

Function global_change:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9d9mu
function name:  global_change
number of ops:  5
compiled vars:  !0 = $i, !1 = $PHORUM
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        BIND_GLOBAL                                              !1, 'PHORUM'
          2        ASSIGN_DIM                                               !1, 0
          3        OP_DATA                                                  !0
          4      > RETURN                                                   null

End of function global_change

Function globals_change:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9d9mu
function name:  GLOBALS_change
number of ops:  5
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        FETCH_W                      global              $1      'PHORUM'
          2        ASSIGN_DIM                                               $1, 0
          3        OP_DATA                                                  !0
          4      > RETURN                                                   null

End of function globals_change

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
192.27 ms | 1011 KiB | 24 Q