3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array('test1', 'test2', 'test3', 'test4'); $var = 'test'; $iterations = 1000000; $start = microtime(true); for($i = 0; $i < $iterations; ++$i) { if ($var != 'test1' && $var != 'test2' && $var != 'test3' && $var != 'test4') {} } $end = microtime(true); print "multiple comparisons: \n". ($end - $start)."\n"; $start2 = microtime(true); for($i = 0; $i < $iterations; ++$i) { if (!in_array($var, $array) ) {} } $end2 = microtime(true); print "in_array: \n".($end2 - $start2)."\n"; $start = microtime(true); $array_flip = array_flip($array); for($i = 0; $i < $iterations; ++$i) { if (!isset($array_flip[$var])) {} } $end = microtime(true); print "array_flip() outside loop measured + isset(): \n".($end - $start)."\n"; $array_flip = array_flip($array); $start = microtime(true); for($i = 0; $i < $iterations; ++$i) { if (!isset($array_flip[$var])) {} } $end = microtime(true); print "array_flip() outside loop not measured + isset(): \n".($end - $start)."\n"; $start = microtime(true); for($i = 0; $i < $iterations; ++$i) { foreach ($array as $entry) { if ($entry == $var) {} } } $end = microtime(true); print "foreach and compoarison: \n".($end - $start)."\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 9
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 37
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 64
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 92
Branch analysis from position: 92
2 jumps found. (Code = 44) Position 1 = 94, Position 2 = 88
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 115
Branch analysis from position: 115
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 108
Branch analysis from position: 117
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 108
2 jumps found. (Code = 77) Position 1 = 109, Position 2 = 113
Branch analysis from position: 109
2 jumps found. (Code = 78) Position 1 = 110, Position 2 = 113
Branch analysis from position: 110
2 jumps found. (Code = 43) Position 1 = 112, Position 2 = 112
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
Branch analysis from position: 112
Branch analysis from position: 113
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 108
Branch analysis from position: 117
Branch analysis from position: 108
Branch analysis from position: 113
Branch analysis from position: 88
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 91
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 94, Position 2 = 88
Branch analysis from position: 94
Branch analysis from position: 88
Branch analysis from position: 91
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 64
Branch analysis from position: 70
Branch analysis from position: 64
Branch analysis from position: 67
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 37
Branch analysis from position: 46
Branch analysis from position: 37
Branch analysis from position: 43
Branch analysis from position: 9
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 9
Branch analysis from position: 23
Branch analysis from position: 9
Branch analysis from position: 20
Branch analysis from position: 19
Branch analysis from position: 16
Branch analysis from position: 13
filename:       /in/OA2S7
function name:  (null)
number of ops:  126
compiled vars:  !0 = $array, !1 = $var, !2 = $iterations, !3 = $start, !4 = $i, !5 = $end, !6 = $start2, !7 = $end2, !8 = $array_flip, !9 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 'test'
    5     2        ASSIGN                                                   !2, 1000000
    7     3        INIT_FCALL                                               'microtime'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $13     
          6        ASSIGN                                                   !3, $13
    8     7        ASSIGN                                                   !4, 0
          8      > JMP                                                      ->21
    9     9    >   IS_NOT_EQUAL                                     ~16     !1, 'test1'
         10      > JMPZ_EX                                          ~16     ~16, ->13
         11    >   IS_NOT_EQUAL                                     ~17     !1, 'test2'
         12        BOOL                                             ~16     ~17
         13    > > JMPZ_EX                                          ~16     ~16, ->16
         14    >   IS_NOT_EQUAL                                     ~18     !1, 'test3'
         15        BOOL                                             ~16     ~18
         16    > > JMPZ_EX                                          ~16     ~16, ->19
         17    >   IS_NOT_EQUAL                                     ~19     !1, 'test4'
         18        BOOL                                             ~16     ~19
         19    > > JMPZ                                                     ~16, ->20
    8    20    >   PRE_INC                                                  !4
         21    >   IS_SMALLER                                               !4, !2
         22      > JMPNZ                                                    ~21, ->9
   11    23    >   INIT_FCALL                                               'microtime'
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $22     
         26        ASSIGN                                                   !5, $22
   13    27        SUB                                              ~24     !5, !3
         28        CONCAT                                           ~25     'multiple+comparisons%3A+%0A', ~24
         29        CONCAT                                           ~26     ~25, '%0A'
         30        ECHO                                                     ~26
   15    31        INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $27     
         34        ASSIGN                                                   !6, $27
   16    35        ASSIGN                                                   !4, 0
         36      > JMP                                                      ->44
   17    37    >   INIT_FCALL                                               'in_array'
         38        SEND_VAR                                                 !1
         39        SEND_VAR                                                 !0
         40        DO_ICALL                                         $30     
         41        BOOL_NOT                                         ~31     $30
         42      > JMPZ                                                     ~31, ->43
   16    43    >   PRE_INC                                                  !4
         44    >   IS_SMALLER                                               !4, !2
         45      > JMPNZ                                                    ~33, ->37
   19    46    >   INIT_FCALL                                               'microtime'
         47        SEND_VAL                                                 <true>
         48        DO_ICALL                                         $34     
         49        ASSIGN                                                   !7, $34
   21    50        SUB                                              ~36     !7, !6
         51        CONCAT                                           ~37     'in_array%3A+%0A', ~36
         52        CONCAT                                           ~38     ~37, '%0A'
         53        ECHO                                                     ~38
   23    54        INIT_FCALL                                               'microtime'
         55        SEND_VAL                                                 <true>
         56        DO_ICALL                                         $39     
         57        ASSIGN                                                   !3, $39
   24    58        INIT_FCALL                                               'array_flip'
         59        SEND_VAR                                                 !0
         60        DO_ICALL                                         $41     
         61        ASSIGN                                                   !8, $41
   26    62        ASSIGN                                                   !4, 0
         63      > JMP                                                      ->68
   27    64    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~44     !8, !1
         65        BOOL_NOT                                         ~45     ~44
         66      > JMPZ                                                     ~45, ->67
   26    67    >   PRE_INC                                                  !4
         68    >   IS_SMALLER                                               !4, !2
         69      > JMPNZ                                                    ~47, ->64
   29    70    >   INIT_FCALL                                               'microtime'
         71        SEND_VAL                                                 <true>
         72        DO_ICALL                                         $48     
         73        ASSIGN                                                   !5, $48
   30    74        SUB                                              ~50     !5, !3
         75        CONCAT                                           ~51     'array_flip%28%29+outside+loop+measured+%2B+isset%28%29%3A+%0A', ~50
         76        CONCAT                                           ~52     ~51, '%0A'
         77        ECHO                                                     ~52
   32    78        INIT_FCALL                                               'array_flip'
         79        SEND_VAR                                                 !0
         80        DO_ICALL                                         $53     
         81        ASSIGN                                                   !8, $53
   33    82        INIT_FCALL                                               'microtime'
         83        SEND_VAL                                                 <true>
         84        DO_ICALL                                         $55     
         85        ASSIGN                                                   !3, $55
   35    86        ASSIGN                                                   !4, 0
         87      > JMP                                                      ->92
   36    88    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~58     !8, !1
         89        BOOL_NOT                                         ~59     ~58
         90      > JMPZ                                                     ~59, ->91
   35    91    >   PRE_INC                                                  !4
         92    >   IS_SMALLER                                               !4, !2
         93      > JMPNZ                                                    ~61, ->88
   38    94    >   INIT_FCALL                                               'microtime'
         95        SEND_VAL                                                 <true>
         96        DO_ICALL                                         $62     
         97        ASSIGN                                                   !5, $62
   39    98        SUB                                              ~64     !5, !3
         99        CONCAT                                           ~65     'array_flip%28%29+outside+loop+not+measured+%2B+isset%28%29%3A+%0A', ~64
        100        CONCAT                                           ~66     ~65, '%0A'
        101        ECHO                                                     ~66
   41   102        INIT_FCALL                                               'microtime'
        103        SEND_VAL                                                 <true>
        104        DO_ICALL                                         $67     
        105        ASSIGN                                                   !3, $67
   43   106        ASSIGN                                                   !4, 0
        107      > JMP                                                      ->115
   44   108    > > FE_RESET_R                                       $70     !0, ->113
        109    > > FE_FETCH_R                                               $70, !9, ->113
   45   110    >   IS_EQUAL                                                 !9, !1
        111      > JMPZ                                                     ~71, ->112
   44   112    > > JMP                                                      ->109
        113    >   FE_FREE                                                  $70
   43   114        PRE_INC                                                  !4
        115    >   IS_SMALLER                                               !4, !2
        116      > JMPNZ                                                    ~73, ->108
   48   117    >   INIT_FCALL                                               'microtime'
        118        SEND_VAL                                                 <true>
        119        DO_ICALL                                         $74     
        120        ASSIGN                                                   !5, $74
   49   121        SUB                                              ~76     !5, !3
        122        CONCAT                                           ~77     'foreach+and+compoarison%3A+%0A', ~76
        123        CONCAT                                           ~78     ~77, '%0A'
        124        ECHO                                                     ~78
        125      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.41 ms | 1408 KiB | 19 Q