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; } $tests = 10; $tests2 = 0; for($i = 0;$i<$tests;$i++) { $tests2 += runTest2(); } $start2 = $tests2 / $tests; $tests1 = 0; for($i = 0;$i<$tests;$i++) { $tests1 += runTest1(); } $start1 = $tests1 / $tests; 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 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 4
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 15
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 37
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 51
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 37
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 15
Branch analysis from position: 21
Branch analysis from position: 15
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 4
Branch analysis from position: 10
Branch analysis from position: 4
filename:       /in/PKE8G
function name:  (null)
number of ops:  52
compiled vars:  !0 = $tests, !1 = $tests2, !2 = $i, !3 = $start2, !4 = $tests1, !5 = $start1, !6 = $perc
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   ASSIGN                                                   !0, 10
   47     1        ASSIGN                                                   !1, 0
   48     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->8
   49     4    >   INIT_FCALL                                               'runtest2'
          5        DO_FCALL                                      0  $10     
          6        ASSIGN_OP                                     1          !1, $10
   48     7        PRE_INC                                                  !2
          8    >   IS_SMALLER                                               !2, !0
          9      > JMPNZ                                                    ~13, ->4
   51    10    >   DIV                                              ~14     !1, !0
         11        ASSIGN                                                   !3, ~14
   54    12        ASSIGN                                                   !4, 0
   55    13        ASSIGN                                                   !2, 0
         14      > JMP                                                      ->19
   56    15    >   INIT_FCALL                                               'runtest1'
         16        DO_FCALL                                      0  $18     
         17        ASSIGN_OP                                     1          !4, $18
   55    18        PRE_INC                                                  !2
         19    >   IS_SMALLER                                               !2, !0
         20      > JMPNZ                                                    ~21, ->15
   58    21    >   DIV                                              ~22     !4, !0
         22        ASSIGN                                                   !5, ~22
   61    23        IS_SMALLER                                               !5, !3
         24      > JMPZ                                                     ~24, ->37
   62    25    >   INIT_FCALL                                               'round'
         26        DIV                                              ~25     !3, !5
         27        MUL                                              ~26     ~25, 100
         28        SEND_VAL                                                 ~26
         29        SEND_VAL                                                 2
         30        DO_ICALL                                         $27     
         31        SUB                                              ~28     100, $27
         32        ASSIGN                                                   !6, ~28
   63    33        NOP                                                      
         34        FAST_CONCAT                                      ~30     'Test1+is+', !6
         35        CONCAT                                           ~31     ~30, '%25+faster+than+Test2'
         36        ECHO                                                     ~31
   67    37    >   IS_SMALLER                                               !3, !5
         38      > JMPZ                                                     ~32, ->51
   68    39    >   INIT_FCALL                                               'round'
         40        DIV                                              ~33     !5, !3
         41        MUL                                              ~34     ~33, 100
         42        SEND_VAL                                                 ~34
         43        SEND_VAL                                                 2
         44        DO_ICALL                                         $35     
         45        SUB                                              ~36     100, $35
         46        ASSIGN                                                   !6, ~36
   69    47        NOP                                                      
         48        FAST_CONCAT                                      ~38     'Test2+is+', !6
         49        CONCAT                                           ~39     ~38, '%25+faster+than+Test1'
         50        ECHO                                                     ~39
   70    51    > > 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/PKE8G
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/PKE8G
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/PKE8G
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/PKE8G
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:
154.72 ms | 1411 KiB | 23 Q