3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_in_array($a) { $valid = array('a', 'b', 'c', 'd'); if (in_array($a, $valid)) { return true; } return false; } function test_array_flip_isset($a) { $valid = array('a', 'b', 'c', 'd'); $valid = array_flip($valid); if (isset($valid[$a])) { return true; } return false; } function test_isset($a) { $valid = array('a' => true, 'b' => true, 'c' => true, 'd' => true); if (isset($valid[$a])) { return true; } return false; } function test_empty($a) { $valid = array('a' => true, 'b' => true, 'c' => true, 'd' => true); if (empty($valid[$a])) { return false; } return true; } function test_not_empty($a) { $valid = array('a' => true, 'b' => true, 'c' => true, 'd' => true); if (!empty($valid[$a])) { return true; } return false; } function test_array_key_exists($a) { $valid = array('a' => true, 'b' => true, 'c' => true, 'd' => true); if (array_key_exists($a, $valid)) { return true; } return false; } function test_switch($a) { switch ($a) { case 'a': case 'b': case 'c': case 'd': return true; default: // do nothing break; } return false; } function test_equals($a) { if (($a == 'a') || ($a == 'b') || ($a == 'c') || ($a == 'd')) { return true; } return false; } function test_same($a) { if (($a === 'a') || ($a === 'b') || ($a === 'c') || ($a === 'd')) { return true; } return false; } $randomValues = array(); $exp = 2; for ($i = 0; $i < pow(10, $exp); $i++) { $randomValues[] = chr(mt_rand(65, 132)); } echo '<strong>10^' . $exp . ' random letters</strong><br/><br/>'; $functions = array( 'test_switch', 'test_in_array', 'test_array_flip_isset', 'test_isset', 'test_empty', 'test_not_empty', 'test_array_key_exists', 'test_equals', 'test_same', ); $baseline = null; foreach ($functions as $func) { $start = microtime(true); foreach ($randomValues as $value) { $func($value); } $end = microtime(true); if ($baseline === null) { echo $func . ': ' . number_format($end - $start, 2) . ' s<br/>'; } else { echo $func . ': ' . number_format($end - $start, 2) . ' s ' . number_format(($end - $start) / $baseline * 100, 2) . '% <br/>'; } if ($func == 'test_switch') { $baseline = $end - $start; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 77
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 77
Branch analysis from position: 27
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 37
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 54
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 76
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
Branch analysis from position: 76
Branch analysis from position: 37
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 4
Branch analysis from position: 20
Branch analysis from position: 4
filename:       /in/d1sJP
function name:  (null)
number of ops:  79
compiled vars:  !0 = $randomValues, !1 = $exp, !2 = $i, !3 = $functions, !4 = $baseline, !5 = $func, !6 = $start, !7 = $value, !8 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   90     0  E >   ASSIGN                                                   !0, <array>
   91     1        ASSIGN                                                   !1, 2
   92     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->14
   93     4    >   INIT_FCALL                                               'chr'
          5        INIT_FCALL                                               'mt_rand'
          6        SEND_VAL                                                 65
          7        SEND_VAL                                                 132
          8        DO_ICALL                                         $13     
          9        SEND_VAR                                                 $13
         10        DO_ICALL                                         $14     
         11        ASSIGN_DIM                                               !0
         12        OP_DATA                                                  $14
   92    13        PRE_INC                                                  !2
         14    >   INIT_FCALL                                               'pow'
         15        SEND_VAL                                                 10
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $16     
         18        IS_SMALLER                                               !2, $16
         19      > JMPNZ                                                    ~17, ->4
   95    20    >   CONCAT                                           ~18     '%3Cstrong%3E10%5E', !1
         21        CONCAT                                           ~19     ~18, '+random+letters%3C%2Fstrong%3E%3Cbr%2F%3E%3Cbr%2F%3E'
         22        ECHO                                                     ~19
   98    23        ASSIGN                                                   !3, <array>
  110    24        ASSIGN                                                   !4, null
  111    25      > FE_RESET_R                                       $22     !3, ->77
         26    > > FE_FETCH_R                                               $22, !5, ->77
  112    27    >   INIT_FCALL                                               'microtime'
         28        SEND_VAL                                                 <true>
         29        DO_ICALL                                         $23     
         30        ASSIGN                                                   !6, $23
  113    31      > FE_RESET_R                                       $25     !0, ->37
         32    > > FE_FETCH_R                                               $25, !7, ->37
  114    33    >   INIT_DYNAMIC_CALL                                        !5
         34        SEND_VAR_EX                                              !7
         35        DO_FCALL                                      0          
  113    36      > JMP                                                      ->32
         37    >   FE_FREE                                                  $25
  116    38        INIT_FCALL                                               'microtime'
         39        SEND_VAL                                                 <true>
         40        DO_ICALL                                         $27     
         41        ASSIGN                                                   !8, $27
  117    42        TYPE_CHECK                                    2          !4
         43      > JMPZ                                                     ~29, ->54
  118    44    >   CONCAT                                           ~30     !5, '%3A+'
         45        INIT_FCALL                                               'number_format'
         46        SUB                                              ~31     !8, !6
         47        SEND_VAL                                                 ~31
         48        SEND_VAL                                                 2
         49        DO_ICALL                                         $32     
         50        CONCAT                                           ~33     ~30, $32
         51        CONCAT                                           ~34     ~33, '+s%3Cbr%2F%3E'
         52        ECHO                                                     ~34
         53      > JMP                                                      ->72
  120    54    >   CONCAT                                           ~35     !5, '%3A+'
         55        INIT_FCALL                                               'number_format'
         56        SUB                                              ~36     !8, !6
         57        SEND_VAL                                                 ~36
         58        SEND_VAL                                                 2
         59        DO_ICALL                                         $37     
         60        CONCAT                                           ~38     ~35, $37
         61        CONCAT                                           ~39     ~38, '+s+'
         62        INIT_FCALL                                               'number_format'
         63        SUB                                              ~40     !8, !6
         64        DIV                                              ~41     ~40, !4
         65        MUL                                              ~42     ~41, 100
         66        SEND_VAL                                                 ~42
         67        SEND_VAL                                                 2
         68        DO_ICALL                                         $43     
         69        CONCAT                                           ~44     ~39, $43
         70        CONCAT                                           ~45     ~44, '%25+%3Cbr%2F%3E'
         71        ECHO                                                     ~45
  122    72    >   IS_EQUAL                                                 !5, 'test_switch'
         73      > JMPZ                                                     ~46, ->76
  123    74    >   SUB                                              ~47     !8, !6
         75        ASSIGN                                                   !4, ~47
  111    76    > > JMP                                                      ->26
         77    >   FE_FREE                                                  $22
  125    78      > RETURN                                                   1

Function test_in_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d1sJP
function name:  test_in_array
number of ops:  10
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6      > JMPZ                                                     $3, ->8
    6     7    > > RETURN                                                   <true>
    8     8    > > RETURN                                                   <false>
    9     9*     > RETURN                                                   null

End of function test_in_array

Function test_array_flip_isset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d1sJP
function name:  test_array_flip_isset
number of ops:  11
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        ASSIGN                                                   !1, <array>
   14     2        INIT_FCALL                                               'array_flip'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   16     6        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !0
          7      > JMPZ                                                     ~5, ->9
   17     8    > > RETURN                                                   <true>
   19     9    > > RETURN                                                   <false>
   20    10*     > RETURN                                                   null

End of function test_array_flip_isset

Function test_isset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d1sJP
function name:  test_isset
number of ops:  7
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        ASSIGN                                                   !1, <array>
   26     2        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !0
          3      > JMPZ                                                     ~3, ->5
   27     4    > > RETURN                                                   <true>
   29     5    > > RETURN                                                   <false>
   30     6*     > RETURN                                                   null

End of function test_isset

Function test_empty:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d1sJP
function name:  test_empty
number of ops:  7
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   34     1        ASSIGN                                                   !1, <array>
   35     2        ISSET_ISEMPTY_DIM_OBJ                         1          !1, !0
          3      > JMPZ                                                     ~3, ->5
   36     4    > > RETURN                                                   <false>
   38     5    > > RETURN                                                   <true>
   39     6*     > RETURN                                                   null

End of function test_empty

Function test_not_empty:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d1sJP
function name:  test_not_empty
number of ops:  8
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        ASSIGN                                                   !1, <array>
   44     2        ISSET_ISEMPTY_DIM_OBJ                         1  ~3      !1, !0
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->6
   45     5    > > RETURN                                                   <true>
   47     6    > > RETURN                                                   <false>
   48     7*     > RETURN                                                   null

End of function test_not_empty

Function test_array_key_exists:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d1sJP
function name:  test_array_key_exists
number of ops:  7
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   52     1        ASSIGN                                                   !1, <array>
   53     2        ARRAY_KEY_EXISTS                                         !0, !1
          3      > JMPZ                                                     ~3, ->5
   54     4    > > RETURN                                                   <true>
   56     5    > > RETURN                                                   <false>
   57     6*     > RETURN                                                   null

End of function test_array_key_exists

Function test_switch:
Finding entry points
Branch analysis from position: 0
6 jumps found. (Code = 188) Position 1 = 11, Position 2 = 11, Position 3 = 11, Position 4 = 11, Position 5 = 12, Position 6 = 2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
Branch analysis from position: 11
Branch analysis from position: 11
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 11
Branch analysis from position: 11
Branch analysis from position: 11
Branch analysis from position: 11
filename:       /in/d1sJP
function name:  test_switch
number of ops:  15
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
   61     1      > SWITCH_STRING                                            !0, [ 'a':->11, 'b':->11, 'c':->11, 'd':->11, ], ->12
   62     2    >   IS_EQUAL                                                 !0, 'a'
          3      > JMPNZ                                                    ~1, ->11
   63     4    >   IS_EQUAL                                                 !0, 'b'
          5      > JMPNZ                                                    ~1, ->11
   64     6    >   IS_EQUAL                                                 !0, 'c'
          7      > JMPNZ                                                    ~1, ->11
   65     8    >   IS_EQUAL                                                 !0, 'd'
          9      > JMPNZ                                                    ~1, ->11
         10    > > JMP                                                      ->12
   66    11    > > RETURN                                                   <true>
   69    12    > > JMP                                                      ->13
   71    13    > > RETURN                                                   <false>
   72    14*     > RETURN                                                   null

End of function test_switch

Function test_equals:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
Branch analysis from position: 8
Branch analysis from position: 5
filename:       /in/d1sJP
function name:  test_equals
number of ops:  15
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   RECV                                             !0      
   76     1        IS_EQUAL                                         ~1      !0, 'a'
          2      > JMPNZ_EX                                         ~1      ~1, ->5
          3    >   IS_EQUAL                                         ~2      !0, 'b'
          4        BOOL                                             ~1      ~2
          5    > > JMPNZ_EX                                         ~1      ~1, ->8
          6    >   IS_EQUAL                                         ~3      !0, 'c'
          7        BOOL                                             ~1      ~3
          8    > > JMPNZ_EX                                         ~1      ~1, ->11
          9    >   IS_EQUAL                                         ~4      !0, 'd'
         10        BOOL                                             ~1      ~4
         11    > > JMPZ                                                     ~1, ->13
   77    12    > > RETURN                                                   <true>
   79    13    > > RETURN                                                   <false>
   80    14*     > RETURN                                                   null

End of function test_equals

Function test_same:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
Branch analysis from position: 8
Branch analysis from position: 5
filename:       /in/d1sJP
function name:  test_same
number of ops:  15
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   84     1        IS_IDENTICAL                                     ~1      !0, 'a'
          2      > JMPNZ_EX                                         ~1      ~1, ->5
          3    >   IS_IDENTICAL                                     ~2      !0, 'b'
          4        BOOL                                             ~1      ~2
          5    > > JMPNZ_EX                                         ~1      ~1, ->8
          6    >   IS_IDENTICAL                                     ~3      !0, 'c'
          7        BOOL                                             ~1      ~3
          8    > > JMPNZ_EX                                         ~1      ~1, ->11
          9    >   IS_IDENTICAL                                     ~4      !0, 'd'
         10        BOOL                                             ~1      ~4
         11    > > JMPZ                                                     ~1, ->13
   85    12    > > RETURN                                                   <true>
   87    13    > > RETURN                                                   <false>
   88    14*     > RETURN                                                   null

End of function test_same

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.53 ms | 1416 KiB | 27 Q