3v4l.org

run code in 500+ PHP versions simultaneously
<?php $numbersArr = range(1,100,3); Shuffle($numbersArr); $userInput = 7; $start = microtime(true); // Filter array, return values larger than user input $filtered = array_filter($numbersArr, function ($value) use($userInput) { return $value >= $userInput; } ); If(count($filtered)>0){ Echo min($filtered); }else{ Echo "no number larger than user input"; } Echo "\ntime = " . (microtime(true)-$start)*1000; $start2 = microtime(true); $match = false; Foreach($numbersArr as $item){ If($item >= $userInput) If($item < $match || $match == false) $match = $item; } Echo "\n\n" . $match; Echo "\ntime = " . (microtime(true)-$start2)*1000; $start3 = microtime(true); Echo "\n\n"; sort($numbersArr); $lastNumbr = end($numbersArr); if ($userInput <= $lastNumbr) { for ($i = ceil($userInput); $i <= $lastNumbr; $i+=1) { if (in_array($i, $numbersArr)) { echo 'found needle: '. $i; break; } } } else { echo "input number out of range, must be below " . $lastNumbr; } Echo "\ntime = " . (microtime(true)-$start3)*1000;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 53
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 53
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 52
Branch analysis from position: 46
2 jumps found. (Code = 47) Position 1 = 48, Position 2 = 50
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 52
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 52
Branch analysis from position: 50
Branch analysis from position: 52
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 91
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 82
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 87
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
Branch analysis from position: 87
2 jumps found. (Code = 44) Position 1 = 90, Position 2 = 82
Branch analysis from position: 90
Branch analysis from position: 82
Branch analysis from position: 91
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 53
Branch analysis from position: 43
Branch analysis from position: 53
filename:       /in/v9og4
function name:  (null)
number of ops:  101
compiled vars:  !0 = $numbersArr, !1 = $userInput, !2 = $start, !3 = $filtered, !4 = $start2, !5 = $match, !6 = $item, !7 = $start3, !8 = $lastNumbr, !9 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'range'
          1        SEND_VAL                                                     1
          2        SEND_VAL                                                     100
          3        SEND_VAL                                                     3
          4        DO_ICALL                                             $10     
          5        ASSIGN                                                       !0, $10
    4     6        INIT_FCALL                                                   'shuffle'
          7        SEND_REF                                                     !0
          8        DO_ICALL                                                     
    5     9        ASSIGN                                                       !1, 7
    8    10        INIT_FCALL                                                   'microtime'
         11        SEND_VAL                                                     <true>
         12        DO_ICALL                                             $14     
         13        ASSIGN                                                       !2, $14
   11    14        INIT_FCALL                                                   'array_filter'
         15        SEND_VAR                                                     !0
   12    16        DECLARE_LAMBDA_FUNCTION                              ~16     [0]
         17        BIND_LEXICAL                                                 ~16, !1
   14    18        SEND_VAL                                                     ~16
   11    19        DO_ICALL                                             $17     
         20        ASSIGN                                                       !3, $17
   16    21        COUNT                                                ~19     !3
         22        IS_SMALLER                                                   0, ~19
         23      > JMPZ                                                         ~20, ->29
   17    24    >   INIT_FCALL                                                   'min'
         25        SEND_VAR                                                     !3
         26        DO_ICALL                                             $21     
         27        ECHO                                                         $21
   16    28      > JMP                                                          ->30
   19    29    >   ECHO                                                         'no+number+larger+than+user+input'
   21    30    >   INIT_FCALL                                                   'microtime'
         31        SEND_VAL                                                     <true>
         32        DO_ICALL                                             $22     
         33        SUB                                                  ~23     $22, !2
         34        MUL                                                  ~24     ~23, 1000
         35        CONCAT                                               ~25     '%0Atime+%3D+', ~24
         36        ECHO                                                         ~25
   24    37        INIT_FCALL                                                   'microtime'
         38        SEND_VAL                                                     <true>
         39        DO_ICALL                                             $26     
         40        ASSIGN                                                       !4, $26
   25    41        ASSIGN                                                       !5, <false>
   26    42      > FE_RESET_R                                           $29     !0, ->53
         43    > > FE_FETCH_R                                                   $29, !6, ->53
   27    44    >   IS_SMALLER_OR_EQUAL                                          !1, !6
         45      > JMPZ                                                         ~30, ->52
   28    46    >   IS_SMALLER                                           ~31     !6, !5
         47      > JMPNZ_EX                                             ~31     ~31, ->50
         48    >   IS_EQUAL                                             ~32     !5, <false>
         49        BOOL                                                 ~31     ~32
         50    > > JMPZ                                                         ~31, ->52
   29    51    >   ASSIGN                                                       !5, !6
   26    52    > > JMP                                                          ->43
         53    >   FE_FREE                                                      $29
   31    54        CONCAT                                               ~34     '%0A%0A', !5
         55        ECHO                                                         ~34
   32    56        INIT_FCALL                                                   'microtime'
         57        SEND_VAL                                                     <true>
         58        DO_ICALL                                             $35     
         59        SUB                                                  ~36     $35, !4
         60        MUL                                                  ~37     ~36, 1000
         61        CONCAT                                               ~38     '%0Atime+%3D+', ~37
         62        ECHO                                                         ~38
   35    63        INIT_FCALL                                                   'microtime'
         64        SEND_VAL                                                     <true>
         65        DO_ICALL                                             $39     
         66        ASSIGN                                                       !7, $39
   36    67        ECHO                                                         '%0A%0A'
   37    68        INIT_FCALL                                                   'sort'
         69        SEND_REF                                                     !0
         70        DO_ICALL                                                     
   38    71        INIT_FCALL                                                   'end'
         72        SEND_REF                                                     !0
         73        DO_ICALL                                             $42     
         74        ASSIGN                                                       !8, $42
   40    75        IS_SMALLER_OR_EQUAL                                          !1, !8
         76      > JMPZ                                                         ~44, ->91
   41    77    >   INIT_FCALL                                                   'ceil'
         78        SEND_VAR                                                     !1
         79        DO_ICALL                                             $45     
         80        ASSIGN                                                       !9, $45
         81      > JMP                                                          ->88
   42    82    >   FRAMELESS_ICALL_2                in_array            ~47     !9, !0
         83      > JMPZ                                                         ~47, ->87
   43    84    >   CONCAT                                               ~48     'found+needle%3A+', !9
         85        ECHO                                                         ~48
   44    86      > JMP                                                          ->90
   41    87    >   ASSIGN_OP                                         1          !9, 1
         88    >   IS_SMALLER_OR_EQUAL                                          !9, !8
         89      > JMPNZ                                                        ~50, ->82
   40    90    > > JMP                                                          ->93
   48    91    >   CONCAT                                               ~51     'input+number+out+of+range%2C+must+be+below+', !8
         92        ECHO                                                         ~51
   51    93    >   INIT_FCALL                                                   'microtime'
         94        SEND_VAL                                                     <true>
         95        DO_ICALL                                             $52     
         96        SUB                                                  ~53     $52, !7
         97        MUL                                                  ~54     ~53, 1000
         98        CONCAT                                               ~55     '%0Atime+%3D+', ~54
         99        ECHO                                                         ~55
   52   100      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v9og4
function name:  {closure:/in/v9og4:12}
number of ops:  5
compiled vars:  !0 = $value, !1 = $userInput
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   13     2        IS_SMALLER_OR_EQUAL                                  ~2      !1, !0
          3      > RETURN                                                       ~2
   14     4*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.54 ms | 1253 KiB | 21 Q