3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types = 1); $n = "5281"; // checking the first byte is enough //---------------------------------------------------------------------------------------- $st = microtime(TRUE); for($i = 0; $i < 1000000; $i++){ $x = is_numeric($n); } echo number_format(microtime(TRUE) - $st, 10) . "\n"; //---------------------------------------------------------------------------------------- $st = microtime(TRUE); for($i = 0; $i < 1000000; $i++){ $x = is_numeric($n[0]); // check only the first byte - makes it a bit slower tho } echo number_format(microtime(TRUE) - $st, 10) . "\n"; //---------------------------------------------------------------------------------------- $digits = [ 0 => TRUE, 1 => TRUE, 2 => TRUE, 3 => TRUE, 4 => TRUE, 5 => TRUE, 6 => TRUE, 7 => TRUE, 8 => TRUE, 9 => TRUE ]; $st = microtime(TRUE); for($i = 0; $i < 1000000; $i++){ $x = isset($digits[$n[0]]); // fastest solution } echo number_format(microtime(TRUE) - $st, 10) . "\n"; //---------------------------------------------------------------------------------------- $st = microtime(TRUE); for($i = 0; $i < 1000000; $i++){ $x = (String)(Int)$n[0] === $n[0]; // slowest solution } echo number_format(microtime(TRUE) - $st, 10) . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 30
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 55
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
2 jumps found. (Code = 44) Position 1 = 86, Position 2 = 77
Branch analysis from position: 86
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 86, Position 2 = 77
Branch analysis from position: 86
Branch analysis from position: 77
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 55
Branch analysis from position: 61
Branch analysis from position: 55
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 30
Branch analysis from position: 38
Branch analysis from position: 30
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
Branch analysis from position: 7
filename:       /in/RGKJk
function name:  (null)
number of ops:  97
compiled vars:  !0 = $n, !1 = $st, !2 = $i, !3 = $x, !4 = $digits
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '5281'
    7     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
    8     5        ASSIGN                                                   !2, 0
          6      > JMP                                                      ->12
    9     7    >   INIT_FCALL                                               'is_numeric'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !3, $9
    8    11        PRE_INC                                                  !2
         12    >   IS_SMALLER                                               !2, 1000000
         13      > JMPNZ                                                    ~12, ->7
   11    14    >   INIT_FCALL                                               'number_format'
         15        INIT_FCALL                                               'microtime'
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $13     
         18        SUB                                              ~14     $13, !1
         19        SEND_VAL                                                 ~14
         20        SEND_VAL                                                 10
         21        DO_ICALL                                         $15     
         22        CONCAT                                           ~16     $15, '%0A'
         23        ECHO                                                     ~16
   15    24        INIT_FCALL                                               'microtime'
         25        SEND_VAL                                                 <true>
         26        DO_ICALL                                         $17     
         27        ASSIGN                                                   !1, $17
   16    28        ASSIGN                                                   !2, 0
         29      > JMP                                                      ->36
   17    30    >   INIT_FCALL                                               'is_numeric'
         31        FETCH_DIM_R                                      ~20     !0, 0
         32        SEND_VAL                                                 ~20
         33        DO_ICALL                                         $21     
         34        ASSIGN                                                   !3, $21
   16    35        PRE_INC                                                  !2
         36    >   IS_SMALLER                                               !2, 1000000
         37      > JMPNZ                                                    ~24, ->30
   19    38    >   INIT_FCALL                                               'number_format'
         39        INIT_FCALL                                               'microtime'
         40        SEND_VAL                                                 <true>
         41        DO_ICALL                                         $25     
         42        SUB                                              ~26     $25, !1
         43        SEND_VAL                                                 ~26
         44        SEND_VAL                                                 10
         45        DO_ICALL                                         $27     
         46        CONCAT                                           ~28     $27, '%0A'
         47        ECHO                                                     ~28
   23    48        ASSIGN                                                   !4, <array>
   27    49        INIT_FCALL                                               'microtime'
         50        SEND_VAL                                                 <true>
         51        DO_ICALL                                         $30     
         52        ASSIGN                                                   !1, $30
   28    53        ASSIGN                                                   !2, 0
         54      > JMP                                                      ->59
   29    55    >   FETCH_DIM_R                                      ~33     !0, 0
         56        ISSET_ISEMPTY_DIM_OBJ                         0  ~34     !4, ~33
         57        ASSIGN                                                   !3, ~34
   28    58        PRE_INC                                                  !2
         59    >   IS_SMALLER                                               !2, 1000000
         60      > JMPNZ                                                    ~37, ->55
   31    61    >   INIT_FCALL                                               'number_format'
         62        INIT_FCALL                                               'microtime'
         63        SEND_VAL                                                 <true>
         64        DO_ICALL                                         $38     
         65        SUB                                              ~39     $38, !1
         66        SEND_VAL                                                 ~39
         67        SEND_VAL                                                 10
         68        DO_ICALL                                         $40     
         69        CONCAT                                           ~41     $40, '%0A'
         70        ECHO                                                     ~41
   35    71        INIT_FCALL                                               'microtime'
         72        SEND_VAL                                                 <true>
         73        DO_ICALL                                         $42     
         74        ASSIGN                                                   !1, $42
   36    75        ASSIGN                                                   !2, 0
         76      > JMP                                                      ->84
   37    77    >   FETCH_DIM_R                                      ~45     !0, 0
         78        CAST                                          4  ~46     ~45
         79        CAST                                          6  ~47     ~46
         80        FETCH_DIM_R                                      ~48     !0, 0
         81        IS_IDENTICAL                                     ~49     ~47, ~48
         82        ASSIGN                                                   !3, ~49
   36    83        PRE_INC                                                  !2
         84    >   IS_SMALLER                                               !2, 1000000
         85      > JMPNZ                                                    ~52, ->77
   39    86    >   INIT_FCALL                                               'number_format'
         87        INIT_FCALL                                               'microtime'
         88        SEND_VAL                                                 <true>
         89        DO_ICALL                                         $53     
         90        SUB                                              ~54     $53, !1
         91        SEND_VAL                                                 ~54
         92        SEND_VAL                                                 10
         93        DO_ICALL                                         $55     
         94        CONCAT                                           ~56     $55, '%0A'
         95        ECHO                                                     ~56
         96      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.23 ms | 1404 KiB | 19 Q