3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_1($nb) { $t = microtime(true); $a = 'f'; $t = microtime(true); $b = ''; $t = microtime(true); for ($u=0; $u<$nb; $u++) { if ($a==='a') { $b .= $a; } else if ($a==='b') { $b .= $a; } else if ($a==='c') { $b .= $a; } else if ($a==='d') { $b .= $a; } else if ($a==='e') { $b .= $a; } else if ($a==='f') { $b .= $a; } } return (microtime(true) - $t); } function test_2($nb) { $a = 'f'; $b = ''; $t = microtime(true); for ($u=0; $u<$nb; $u++) { switch ($a) { case 'a': $b .= $a; case 'b': $b .= $a; case 'c': $b .= $a; case 'd': $b .= $a; case 'e': $b .= $a; case 'f': $b .= $a; } } return (microtime(true) - $t); } $nb = 10000000; echo 'test_1: '.test_1($nb)."\n"; echo 'test_2: '.test_2($nb)."\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a6S6v
function name:  (null)
number of ops:  14
compiled vars:  !0 = $nb
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   ASSIGN                                                   !0, 10000000
   66     1        INIT_FCALL                                               'test_1'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        CONCAT                                           ~3      'test_1%3A+', $2
          5        CONCAT                                           ~4      ~3, '%0A'
          6        ECHO                                                     ~4
   67     7        INIT_FCALL                                               'test_2'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $5      
         10        CONCAT                                           ~6      'test_2%3A+', $5
         11        CONCAT                                           ~7      ~6, '%0A'
         12        ECHO                                                     ~7
         13      > RETURN                                                   1

Function test_1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 17
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 17
Branch analysis from position: 43
Branch analysis from position: 17
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 40
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 17
Branch analysis from position: 43
Branch analysis from position: 17
Branch analysis from position: 40
filename:       /in/a6S6v
function name:  test_1
number of ops:  49
compiled vars:  !0 = $nb, !1 = $t, !2 = $a, !3 = $b, !4 = $u
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
    6     5        ASSIGN                                                   !2, 'f'
    7     6        INIT_FCALL                                               'microtime'
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !1, $8
    8    10        ASSIGN                                                   !3, ''
    9    11        INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !1, $11
   11    15        ASSIGN                                                   !4, 0
         16      > JMP                                                      ->41
   13    17    >   IS_IDENTICAL                                             !2, 'a'
         18      > JMPZ                                                     ~14, ->21
   15    19    >   ASSIGN_OP                                     8          !3, !2
         20      > JMP                                                      ->40
   16    21    >   IS_IDENTICAL                                             !2, 'b'
         22      > JMPZ                                                     ~16, ->25
   18    23    >   ASSIGN_OP                                     8          !3, !2
         24      > JMP                                                      ->40
   19    25    >   IS_IDENTICAL                                             !2, 'c'
         26      > JMPZ                                                     ~18, ->29
   21    27    >   ASSIGN_OP                                     8          !3, !2
         28      > JMP                                                      ->40
   22    29    >   IS_IDENTICAL                                             !2, 'd'
         30      > JMPZ                                                     ~20, ->33
   24    31    >   ASSIGN_OP                                     8          !3, !2
         32      > JMP                                                      ->40
   25    33    >   IS_IDENTICAL                                             !2, 'e'
         34      > JMPZ                                                     ~22, ->37
   27    35    >   ASSIGN_OP                                     8          !3, !2
         36      > JMP                                                      ->40
   28    37    >   IS_IDENTICAL                                             !2, 'f'
         38      > JMPZ                                                     ~24, ->40
   30    39    >   ASSIGN_OP                                     8          !3, !2
   11    40    >   PRE_INC                                                  !4
         41    >   IS_SMALLER                                               !4, !0
         42      > JMPNZ                                                    ~27, ->17
   34    43    >   INIT_FCALL                                               'microtime'
         44        SEND_VAL                                                 <true>
         45        DO_ICALL                                         $28     
         46        SUB                                              ~29     $28, !1
         47      > RETURN                                                   ~29
   35    48*     > RETURN                                                   null

End of function test_1

Function test_2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 9
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
8 jumps found. (Code = 188) Position 1 = 23, Position 2 = 24, Position 3 = 25, Position 4 = 26, Position 5 = 27, Position 6 = 28, Position 7 = 29, Position 8 = 10
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 9
Branch analysis from position: 32
Branch analysis from position: 9
Branch analysis from position: 24
Branch analysis from position: 25
Branch analysis from position: 26
Branch analysis from position: 27
Branch analysis from position: 28
Branch analysis from position: 29
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 28
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 28
Branch analysis from position: 27
Branch analysis from position: 26
Branch analysis from position: 25
Branch analysis from position: 24
Branch analysis from position: 23
filename:       /in/a6S6v
function name:  test_2
number of ops:  38
compiled vars:  !0 = $nb, !1 = $a, !2 = $b, !3 = $t, !4 = $u
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   39     1        ASSIGN                                                   !1, 'f'
   40     2        ASSIGN                                                   !2, ''
   41     3        INIT_FCALL                                               'microtime'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !3, $7
   43     7        ASSIGN                                                   !4, 0
          8      > JMP                                                      ->30
   45     9    > > SWITCH_STRING                                            !1, [ 'a':->23, 'b':->24, 'c':->25, 'd':->26, 'e':->27, 'f':->28, ], ->29
   47    10    >   IS_EQUAL                                                 !1, 'a'
         11      > JMPNZ                                                    ~10, ->23
   49    12    >   IS_EQUAL                                                 !1, 'b'
         13      > JMPNZ                                                    ~10, ->24
   51    14    >   IS_EQUAL                                                 !1, 'c'
         15      > JMPNZ                                                    ~10, ->25
   53    16    >   IS_EQUAL                                                 !1, 'd'
         17      > JMPNZ                                                    ~10, ->26
   55    18    >   IS_EQUAL                                                 !1, 'e'
         19      > JMPNZ                                                    ~10, ->27
   57    20    >   IS_EQUAL                                                 !1, 'f'
         21      > JMPNZ                                                    ~10, ->28
         22    > > JMP                                                      ->29
   48    23    >   ASSIGN_OP                                     8          !2, !1
   50    24    >   ASSIGN_OP                                     8          !2, !1
   52    25    >   ASSIGN_OP                                     8          !2, !1
   54    26    >   ASSIGN_OP                                     8          !2, !1
   56    27    >   ASSIGN_OP                                     8          !2, !1
   58    28    >   ASSIGN_OP                                     8          !2, !1
   43    29    >   PRE_INC                                                  !4
         30    >   IS_SMALLER                                               !4, !0
         31      > JMPNZ                                                    ~18, ->9
   62    32    >   INIT_FCALL                                               'microtime'
         33        SEND_VAL                                                 <true>
         34        DO_ICALL                                         $19     
         35        SUB                                              ~20     $19, !3
         36      > RETURN                                                   ~20
   63    37*     > RETURN                                                   null

End of function test_2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.65 ms | 1411 KiB | 17 Q