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; } function runTest1() { $start1 = microtime(1); for ($i = 1; $i < 10000; $i++) { test1(); } $start1 -= microtime(1); return $start1; } function runTest2() { $start2 = microtime(1); for ($i = 1; $i < 10000; $i++) { test2(); } $start2 -= microtime(1); return $start2; } $tests2 = 0; for($i = 0;$i<1000;$i++) { $tests2 += runTests2(); } $start2 = $tests2 / 1000; $tests1 = 0; for($i = 0;$i<1000;$i++) { $tests1 += runTests2(); } $start2 = $tests1 / 1000; if ($start1 < $start2) { $perc = 100-round(($start2 / $start1) * 100,2); echo "Test1 is $perc"."% faster than Test2"; } if ($start2 < $start1) { $perc = 100-round(($start1 / $start2) * 100,2); echo "Test2 is $perc"."% faster than Test1"; }
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 = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 36
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 50
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 36
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
Branch analysis from position: 14
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/4gHtI
function name:  (null)
number of ops:  51
compiled vars:  !0 = $tests2, !1 = $i, !2 = $start2, !3 = $tests1, !4 = $start1, !5 = $perc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, 0
   45     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->7
   46     3    >   INIT_FCALL_BY_NAME                                       'runTests2'
          4        DO_FCALL                                      0  $8      
          5        ASSIGN_OP                                     1          !0, $8
   45     6        PRE_INC                                                  !1
          7    >   IS_SMALLER                                               !1, 1000
          8      > JMPNZ                                                    ~11, ->3
   48     9    >   DIV                                              ~12     !0, 1000
         10        ASSIGN                                                   !2, ~12
   51    11        ASSIGN                                                   !3, 0
   52    12        ASSIGN                                                   !1, 0
         13      > JMP                                                      ->18
   53    14    >   INIT_FCALL_BY_NAME                                       'runTests2'
         15        DO_FCALL                                      0  $16     
         16        ASSIGN_OP                                     1          !3, $16
   52    17        PRE_INC                                                  !1
         18    >   IS_SMALLER                                               !1, 1000
         19      > JMPNZ                                                    ~19, ->14
   55    20    >   DIV                                              ~20     !3, 1000
         21        ASSIGN                                                   !2, ~20
   58    22        IS_SMALLER                                               !4, !2
         23      > JMPZ                                                     ~22, ->36
   59    24    >   INIT_FCALL                                               'round'
         25        DIV                                              ~23     !2, !4
         26        MUL                                              ~24     ~23, 100
         27        SEND_VAL                                                 ~24
         28        SEND_VAL                                                 2
         29        DO_ICALL                                         $25     
         30        SUB                                              ~26     100, $25
         31        ASSIGN                                                   !5, ~26
   60    32        NOP                                                      
         33        FAST_CONCAT                                      ~28     'Test1+is+', !5
         34        CONCAT                                           ~29     ~28, '%25+faster+than+Test2'
         35        ECHO                                                     ~29
   64    36    >   IS_SMALLER                                               !2, !4
         37      > JMPZ                                                     ~30, ->50
   65    38    >   INIT_FCALL                                               'round'
         39        DIV                                              ~31     !4, !2
         40        MUL                                              ~32     ~31, 100
         41        SEND_VAL                                                 ~32
         42        SEND_VAL                                                 2
         43        DO_ICALL                                         $33     
         44        SUB                                              ~34     100, $33
         45        ASSIGN                                                   !5, ~34
   66    46        NOP                                                      
         47        FAST_CONCAT                                      ~36     'Test2+is+', !5
         48        CONCAT                                           ~37     ~36, '%25+faster+than+Test1'
         49        ECHO                                                     ~37
   67    50    > > 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/4gHtI
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/4gHtI
function name:  test2
number of ops:  13
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, 'derp'
   14     1      > SWITCH_STRING                                            !0, [ 'files':->9, 'something':->9, 'Derrr':->9, ], ->10
   15     2    >   IS_EQUAL                                                 !0, 'files'
          3      > JMPNZ                                                    ~2, ->9
   16     4    >   IS_EQUAL                                                 !0, 'something'
          5      > JMPNZ                                                    ~2, ->9
   17     6    >   IS_EQUAL                                                 !0, 'Derrr'
          7      > JMPNZ                                                    ~2, ->9
          8    > > JMP                                                      ->10
   18     9    > > JMP                                                      ->11
   20    10    > > RETURN                                                   null
   22    11    > > RETURN                                                   null
   23    12*     > RETURN                                                   null

End of function test2

Function runtest1:
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 = 62) Position 1 = -2
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/4gHtI
function name:  runTest1
number of ops:  17
compiled vars:  !0 = $start1, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                         $2      
          3        ASSIGN                                                   !0, $2
   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                                                    ~7, ->6
   31    11    >   INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $8      
         14        ASSIGN_OP                                     2          !0, $8
   32    15      > RETURN                                                   !0
   33    16*     > RETURN                                                   null

End of function runtest1

Function runtest2:
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 = 62) Position 1 = -2
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/4gHtI
function name:  runTest2
number of ops:  17
compiled vars:  !0 = $start2, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 1
          2        DO_ICALL                                         $2      
          3        ASSIGN                                                   !0, $2
   37     4        ASSIGN                                                   !1, 1
          5      > JMP                                                      ->9
   38     6    >   INIT_FCALL                                               'test2'
          7        DO_FCALL                                      0          
   37     8        PRE_INC                                                  !1
          9    >   IS_SMALLER                                               !1, 10000
         10      > JMPNZ                                                    ~7, ->6
   40    11    >   INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $8      
         14        ASSIGN_OP                                     2          !0, $8
   41    15      > RETURN                                                   !0
   42    16*     > RETURN                                                   null

End of function runtest2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.98 ms | 1408 KiB | 21 Q