3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('memory_limit', '512M'); 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 = 4; 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 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 8
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 81
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 81
Branch analysis from position: 31
2 jumps found. (Code = 77) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 41
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 58
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 80
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
Branch analysis from position: 80
Branch analysis from position: 41
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 81
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 8
Branch analysis from position: 24
Branch analysis from position: 8
filename:       /in/k6rA1
function name:  (null)
number of ops:  83
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
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'ini_set'
          1        SEND_VAL                                                 'memory_limit'
          2        SEND_VAL                                                 '512M'
          3        DO_ICALL                                                 
   92     4        ASSIGN                                                   !0, <array>
   93     5        ASSIGN                                                   !1, 4
   94     6        ASSIGN                                                   !2, 0
          7      > JMP                                                      ->18
   95     8    >   INIT_FCALL                                               'chr'
          9        INIT_FCALL                                               'mt_rand'
         10        SEND_VAL                                                 65
         11        SEND_VAL                                                 132
         12        DO_ICALL                                         $14     
         13        SEND_VAR                                                 $14
         14        DO_ICALL                                         $15     
         15        ASSIGN_DIM                                               !0
         16        OP_DATA                                                  $15
   94    17        PRE_INC                                                  !2
         18    >   INIT_FCALL                                               'pow'
         19        SEND_VAL                                                 10
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $17     
         22        IS_SMALLER                                               !2, $17
         23      > JMPNZ                                                    ~18, ->8
   97    24    >   CONCAT                                           ~19     '%3Cstrong%3E10%5E', !1
         25        CONCAT                                           ~20     ~19, '+random+letters%3C%2Fstrong%3E%3Cbr%2F%3E%3Cbr%2F%3E'
         26        ECHO                                                     ~20
  100    27        ASSIGN                                                   !3, <array>
  112    28        ASSIGN                                                   !4, null
  113    29      > FE_RESET_R                                       $23     !3, ->81
         30    > > FE_FETCH_R                                               $23, !5, ->81
  114    31    >   INIT_FCALL                                               'microtime'
         32        SEND_VAL                                                 <true>
         33        DO_ICALL                                         $24     
         34        ASSIGN                                                   !6, $24
  115    35      > FE_RESET_R                                       $26     !0, ->41
         36    > > FE_FETCH_R                                               $26, !7, ->41
  116    37    >   INIT_DYNAMIC_CALL                                        !5
         38        SEND_VAR_EX                                              !7
         39        DO_FCALL                                      0          
  115    40      > JMP                                                      ->36
         41    >   FE_FREE                                                  $26
  118    42        INIT_FCALL                                               'microtime'
         43        SEND_VAL                                                 <true>
         44        DO_ICALL                                         $28     
         45        ASSIGN                                                   !8, $28
  119    46        TYPE_CHECK                                    2          !4
         47      > JMPZ                                                     ~30, ->58
  120    48    >   CONCAT                                           ~31     !5, '%3A+'
         49        INIT_FCALL                                               'number_format'
         50        SUB                                              ~32     !8, !6
         51        SEND_VAL                                                 ~32
         52        SEND_VAL                                                 2
         53        DO_ICALL                                         $33     
         54        CONCAT                                           ~34     ~31, $33
         55        CONCAT                                           ~35     ~34, '+s%3Cbr%2F%3E'
         56        ECHO                                                     ~35
         57      > JMP                                                      ->76
  122    58    >   CONCAT                                           ~36     !5, '%3A+'
         59        INIT_FCALL                                               'number_format'
         60        SUB                                              ~37     !8, !6
         61        SEND_VAL                                                 ~37
         62        SEND_VAL                                                 2
         63        DO_ICALL                                         $38     
         64        CONCAT                                           ~39     ~36, $38
         65        CONCAT                                           ~40     ~39, '+s+'
         66        INIT_FCALL                                               'number_format'
         67        SUB                                              ~41     !8, !6
         68        DIV                                              ~42     ~41, !4
         69        MUL                                              ~43     ~42, 100
         70        SEND_VAL                                                 ~43
         71        SEND_VAL                                                 2
         72        DO_ICALL                                         $44     
         73        CONCAT                                           ~45     ~40, $44
         74        CONCAT                                           ~46     ~45, '%25+%3Cbr%2F%3E'
         75        ECHO                                                     ~46
  124    76    >   IS_EQUAL                                                 !5, 'test_switch'
         77      > JMPZ                                                     ~47, ->80
  125    78    >   SUB                                              ~48     !8, !6
         79        ASSIGN                                                   !4, ~48
  113    80    > > JMP                                                      ->30
         81    >   FE_FREE                                                  $23
  127    82      > 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/k6rA1
function name:  test_in_array
number of ops:  10
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, <array>
    7     2        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6      > JMPZ                                                     $3, ->8
    8     7    > > RETURN                                                   <true>
   10     8    > > RETURN                                                   <false>
   11     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/k6rA1
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
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, <array>
   16     2        INIT_FCALL                                               'array_flip'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   18     6        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !0
          7      > JMPZ                                                     ~5, ->9
   19     8    > > RETURN                                                   <true>
   21     9    > > RETURN                                                   <false>
   22    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/k6rA1
function name:  test_isset
number of ops:  7
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        ASSIGN                                                   !1, <array>
   28     2        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !0
          3      > JMPZ                                                     ~3, ->5
   29     4    > > RETURN                                                   <true>
   31     5    > > RETURN                                                   <false>
   32     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/k6rA1
function name:  test_empty
number of ops:  7
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        ASSIGN                                                   !1, <array>
   37     2        ISSET_ISEMPTY_DIM_OBJ                         1          !1, !0
          3      > JMPZ                                                     ~3, ->5
   38     4    > > RETURN                                                   <false>
   40     5    > > RETURN                                                   <true>
   41     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/k6rA1
function name:  test_not_empty
number of ops:  8
compiled vars:  !0 = $a, !1 = $valid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   45     1        ASSIGN                                                   !1, <array>
   46     2        ISSET_ISEMPTY_DIM_OBJ                         1  ~3      !1, !0
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->6
   47     5    > > RETURN                                                   <true>
   49     6    > > RETURN                                                   <false>
   50     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/k6rA1
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
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   54     1        ASSIGN                                                   !1, <array>
   55     2        ARRAY_KEY_EXISTS                                         !0, !1
          3      > JMPZ                                                     ~3, ->5
   56     4    > > RETURN                                                   <true>
   58     5    > > RETURN                                                   <false>
   59     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/k6rA1
function name:  test_switch
number of ops:  15
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
   63     1      > SWITCH_STRING                                            !0, [ 'a':->11, 'b':->11, 'c':->11, 'd':->11, ], ->12
   64     2    >   IS_EQUAL                                                 !0, 'a'
          3      > JMPNZ                                                    ~1, ->11
   65     4    >   IS_EQUAL                                                 !0, 'b'
          5      > JMPNZ                                                    ~1, ->11
   66     6    >   IS_EQUAL                                                 !0, 'c'
          7      > JMPNZ                                                    ~1, ->11
   67     8    >   IS_EQUAL                                                 !0, 'd'
          9      > JMPNZ                                                    ~1, ->11
         10    > > JMP                                                      ->12
   68    11    > > RETURN                                                   <true>
   71    12    > > JMP                                                      ->13
   73    13    > > RETURN                                                   <false>
   74    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/k6rA1
function name:  test_equals
number of ops:  15
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
   78     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
   79    12    > > RETURN                                                   <true>
   81    13    > > RETURN                                                   <false>
   82    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/k6rA1
function name:  test_same
number of ops:  15
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
   86     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
   87    12    > > RETURN                                                   <true>
   89    13    > > RETURN                                                   <false>
   90    14*     > RETURN                                                   null

End of function test_same

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.87 ms | 1416 KiB | 29 Q