3v4l.org

run code in 300+ PHP versions simultaneously
<?php function timeFunc($function, $runs) { $start = microtime(true); for ($i = 0; $i < $runs; $i++) { call_user_func($function); } return (microtime(true) - $start); } function Method1() { $foo = 'some words'; for ($i = 0; $i < 10000; $i++) { $t = "these are $foo"; } } function Method2() { $foo = 'some words'; for ($i = 0; $i < 10000; $i++) { $t = "these are {$foo}"; } } function Method3() { $foo = 'some words'; for ($i = 0; $i < 10000; $i++) { $t = "these are " . $foo; } } $a = timeFunc('Method1', 10); $b = timeFunc('Method2', 10); $c = timeFunc('Method3', 10); echo ($a + $b) / (2 * $a) . "\n"; echo ($a + $c) / (2 * $a) . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Rg8ol
function name:  (null)
number of ops:  26
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'timefunc'
          1        SEND_VAL                                                 'Method1'
          2        SEND_VAL                                                 10
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !0, $3
   33     5        INIT_FCALL                                               'timefunc'
          6        SEND_VAL                                                 'Method2'
          7        SEND_VAL                                                 10
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !1, $5
   34    10        INIT_FCALL                                               'timefunc'
         11        SEND_VAL                                                 'Method3'
         12        SEND_VAL                                                 10
         13        DO_FCALL                                      0  $7      
         14        ASSIGN                                                   !2, $7
   36    15        ADD                                              ~9      !0, !1
         16        MUL                                              ~10     !0, 2
         17        DIV                                              ~11     ~9, ~10
         18        CONCAT                                           ~12     ~11, '%0A'
         19        ECHO                                                     ~12
   37    20        ADD                                              ~13     !0, !2
         21        MUL                                              ~14     !0, 2
         22        DIV                                              ~15     ~13, ~14
         23        CONCAT                                           ~16     ~15, '%0A'
         24        ECHO                                                     ~16
         25      > RETURN                                                   1

Function timefunc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/Rg8ol
function name:  timeFunc
number of ops:  19
compiled vars:  !0 = $function, !1 = $runs, !2 = $start, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !2, $4
    5     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->11
    6     8    >   INIT_USER_CALL                                0          'call_user_func', !0
          9        DO_FCALL                                      0          
    5    10        PRE_INC                                                  !3
         11    >   IS_SMALLER                                               !3, !1
         12      > JMPNZ                                                    ~9, ->8
    8    13    >   INIT_FCALL                                               'microtime'
         14        SEND_VAL                                                 <true>
         15        DO_ICALL                                         $10     
         16        SUB                                              ~11     $10, !2
         17      > RETURN                                                   ~11
    9    18*     > RETURN                                                   null

End of function timefunc

Function method1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 3
Branch analysis from position: 9
Branch analysis from position: 3
filename:       /in/Rg8ol
function name:  Method1
number of ops:  10
compiled vars:  !0 = $foo, !1 = $i, !2 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, 'some+words'
   13     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->7
   14     3    >   NOP                                                      
          4        FAST_CONCAT                                      ~5      'these+are+', !0
          5        ASSIGN                                                   !2, ~5
   13     6        PRE_INC                                                  !1
          7    >   IS_SMALLER                                               !1, 10000
          8      > JMPNZ                                                    ~8, ->3
   16     9    > > RETURN                                                   null

End of function method1

Function method2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 3
Branch analysis from position: 9
Branch analysis from position: 3
filename:       /in/Rg8ol
function name:  Method2
number of ops:  10
compiled vars:  !0 = $foo, !1 = $i, !2 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, 'some+words'
   20     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->7
   21     3    >   NOP                                                      
          4        FAST_CONCAT                                      ~5      'these+are+', !0
          5        ASSIGN                                                   !2, ~5
   20     6        PRE_INC                                                  !1
          7    >   IS_SMALLER                                               !1, 10000
          8      > JMPNZ                                                    ~8, ->3
   23     9    > > RETURN                                                   null

End of function method2

Function method3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 3
Branch analysis from position: 8
Branch analysis from position: 3
filename:       /in/Rg8ol
function name:  Method3
number of ops:  9
compiled vars:  !0 = $foo, !1 = $i, !2 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, 'some+words'
   27     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->6
   28     3    >   CONCAT                                           ~5      'these+are+', !0
          4        ASSIGN                                                   !2, ~5
   27     5        PRE_INC                                                  !1
          6    >   IS_SMALLER                                               !1, 10000
          7      > JMPNZ                                                    ~8, ->3
   30     8    > > RETURN                                                   null

End of function method3

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.97 ms | 1411 KiB | 18 Q