3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test1() { $str = 'derp'; if ($str != 'files' && $str != 'something' && $str != 'Derrr') { return; } return; } function test2() { $str = 'derp'; switch ($str) { case 'files': case 'something': case 'Derrr': break; default: return; } return; } $start1 = microtime(1); for ($i = 1; $i < 10000; $i++) { test1(); } $start1 -= microtime(1); echo "test1: $start1"; $start2 = microtime(1); for ($i = 1; $i < 10000; $i++) { test2(); } $start2 -= microtime(1); echo "\ntest2: $start2\n\n"; if ($start1 < $start2) { $perc = round(($start1 / $start2) * 100,2)-100; echo "Test1 is $perc"."% faster than Test2"; } if ($start2 < $start1) { $perc = round(($start2 / $start1) * 100,2)-100; echo "Test2 is $perc"."% faster than Test1"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 6
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 24
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 51
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 65
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
Branch analysis from position: 51
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 24
Branch analysis from position: 29
Branch analysis from position: 24
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 6
Branch analysis from position: 11
Branch analysis from position: 6
filename:       /in/eMddp
function name:  (null)
number of ops:  66
compiled vars:  !0 = $start1, !1 = $i, !2 = $start2, !3 = $perc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                         $4      
          3        ASSIGN                                                   !0, $4
   28     4        ASSIGN                                                   !1, 1
          5      > JMP                                                      ->9
   29     6    >   INIT_FCALL                                               'test1'
          7        DO_FCALL                                      0          
   28     8        PRE_INC                                                  !1
          9    >   IS_SMALLER                                               !1, 10000
         10      > JMPNZ                                                    ~9, ->6
   31    11    >   INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $10     
         14        ASSIGN_OP                                     2          !0, $10
   32    15        NOP                                                      
         16        FAST_CONCAT                                      ~12     'test1%3A+', !0
         17        ECHO                                                     ~12
   35    18        INIT_FCALL                                               'microtime'
         19        SEND_VAL                                                 1
         20        DO_ICALL                                         $13     
         21        ASSIGN                                                   !2, $13
   36    22        ASSIGN                                                   !1, 1
         23      > JMP                                                      ->27
   37    24    >   INIT_FCALL                                               'test2'
         25        DO_FCALL                                      0          
   36    26        PRE_INC                                                  !1
         27    >   IS_SMALLER                                               !1, 10000
         28      > JMPNZ                                                    ~18, ->24
   39    29    >   INIT_FCALL                                               'microtime'
         30        SEND_VAL                                                 1
         31        DO_ICALL                                         $19     
         32        ASSIGN_OP                                     2          !2, $19
   40    33        ROPE_INIT                                     3  ~22     '%0Atest2%3A+'
         34        ROPE_ADD                                      1  ~22     ~22, !2
         35        ROPE_END                                      2  ~21     ~22, '%0A%0A'
         36        ECHO                                                     ~21
   43    37        IS_SMALLER                                               !0, !2
         38      > JMPZ                                                     ~24, ->51
   44    39    >   INIT_FCALL                                               'round'
         40        DIV                                              ~25     !0, !2
         41        MUL                                              ~26     ~25, 100
         42        SEND_VAL                                                 ~26
         43        SEND_VAL                                                 2
         44        DO_ICALL                                         $27     
         45        SUB                                              ~28     $27, 100
         46        ASSIGN                                                   !3, ~28
   45    47        NOP                                                      
         48        FAST_CONCAT                                      ~30     'Test1+is+', !3
         49        CONCAT                                           ~31     ~30, '%25+faster+than+Test2'
         50        ECHO                                                     ~31
   49    51    >   IS_SMALLER                                               !2, !0
         52      > JMPZ                                                     ~32, ->65
   50    53    >   INIT_FCALL                                               'round'
         54        DIV                                              ~33     !2, !0
         55        MUL                                              ~34     ~33, 100
         56        SEND_VAL                                                 ~34
         57        SEND_VAL                                                 2
         58        DO_ICALL                                         $35     
         59        SUB                                              ~36     $35, 100
         60        ASSIGN                                                   !3, ~36
   51    61        NOP                                                      
         62        FAST_CONCAT                                      ~38     'Test2+is+', !3
         63        CONCAT                                           ~39     ~38, '%25+faster+than+Test1'
         64        ECHO                                                     ~39
   52    65    > > RETURN                                                   1

Function test1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
Branch analysis from position: 5
filename:       /in/eMddp
function name:  test1
number of ops:  12
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                   !0, 'derp'
    6     1        IS_NOT_EQUAL                                     ~2      !0, 'files'
          2      > JMPZ_EX                                          ~2      ~2, ->5
          3    >   IS_NOT_EQUAL                                     ~3      !0, 'something'
          4        BOOL                                             ~2      ~3
          5    > > JMPZ_EX                                          ~2      ~2, ->8
          6    >   IS_NOT_EQUAL                                     ~4      !0, 'Derrr'
          7        BOOL                                             ~2      ~4
          8    > > JMPZ                                                     ~2, ->10
    7     9    > > RETURN                                                   null
    9    10    > > RETURN                                                   null
   10    11*     > RETURN                                                   null

End of function test1

Function test2:
Finding entry points
Branch analysis from position: 0
5 jumps found. (Code = 188) Position 1 = 9, Position 2 = 9, Position 3 = 9, Position 4 = 10, Position 5 = 2
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
Branch analysis from position: 9
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 9
Branch analysis from position: 9
Branch analysis from position: 9
filename:       /in/eMddp
function name:  test2
number of ops:  13
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                   !0, 'derp'
   16     1      > SWITCH_STRING                                            !0, [ 'files':->9, 'something':->9, 'Derrr':->9, ], ->10
   17     2    >   IS_EQUAL                                                 !0, 'files'
          3      > JMPNZ                                                    ~2, ->9
   18     4    >   IS_EQUAL                                                 !0, 'something'
          5      > JMPNZ                                                    ~2, ->9
   19     6    >   IS_EQUAL                                                 !0, 'Derrr'
          7      > JMPNZ                                                    ~2, ->9
          8    > > JMP                                                      ->10
   20     9    > > JMP                                                      ->11
   22    10    > > RETURN                                                   null
   24    11    > > RETURN                                                   null
   25    12*     > RETURN                                                   null

End of function test2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.18 ms | 1396 KiB | 21 Q