3v4l.org

run code in 300+ PHP versions simultaneously
<?php function count_digits($digit, $base) { // TODO: add type validation return $digit >= 10 ? 1 + count_digits($digit / $base) : 1; } $digit = 1554; $tries = 10000; var_dump(count_digits($digit)); $start = microtime(true); for ($i = 0; $i < $tries; $i++) { count_digits($digit); } echo (microtime(true) - $start).PHP_EOL; $start = microtime(true); for ($i = 0; $i < $tries; $i++) { strlen($digit); } echo (microtime(true) - $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 = 20, Position 2 = 14
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 32
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 32
Branch analysis from position: 37
Branch analysis from position: 32
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 14
Branch analysis from position: 20
Branch analysis from position: 14
filename:       /in/t0o47
function name:  (null)
number of ops:  43
compiled vars:  !0 = $digit, !1 = $tries, !2 = $start, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                   !0, 1554
    9     1        ASSIGN                                                   !1, 10000
   11     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'count_digits'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $6      
          6        SEND_VAR                                                 $6
          7        DO_ICALL                                                 
   13     8        INIT_FCALL                                               'microtime'
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !2, $8
   14    12        ASSIGN                                                   !3, 0
         13      > JMP                                                      ->18
   15    14    >   INIT_FCALL                                               'count_digits'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0          
   14    17        PRE_INC                                                  !3
         18    >   IS_SMALLER                                               !3, !1
         19      > JMPNZ                                                    ~13, ->14
   17    20    >   INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $14     
         23        SUB                                              ~15     $14, !2
         24        CONCAT                                           ~16     ~15, '%0A'
         25        ECHO                                                     ~16
   19    26        INIT_FCALL                                               'microtime'
         27        SEND_VAL                                                 <true>
         28        DO_ICALL                                         $17     
         29        ASSIGN                                                   !2, $17
   20    30        ASSIGN                                                   !3, 0
         31      > JMP                                                      ->35
   21    32    >   STRLEN                                           ~20     !0
         33        FREE                                                     ~20
   20    34        PRE_INC                                                  !3
         35    >   IS_SMALLER                                               !3, !1
         36      > JMPNZ                                                    ~22, ->32
   23    37    >   INIT_FCALL                                               'microtime'
         38        SEND_VAL                                                 <true>
         39        DO_ICALL                                         $23     
         40        SUB                                              ~24     $23, !2
         41        ECHO                                                     ~24
         42      > RETURN                                                   1

Function count_digits:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/t0o47
function name:  count_digits
number of ops:  14
compiled vars:  !0 = $digit, !1 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        IS_SMALLER_OR_EQUAL                                      10, !0
          3      > JMPZ                                                     ~2, ->11
          4    >   INIT_FCALL_BY_NAME                                       'count_digits'
          5        DIV                                              ~3      !0, !1
          6        SEND_VAL_EX                                              ~3
          7        DO_FCALL                                      0  $4      
          8        ADD                                              ~5      1, $4
          9        QM_ASSIGN                                        ~6      ~5
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~6      1
         12    > > RETURN                                                   ~6
    6    13*     > RETURN                                                   null

End of function count_digits

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.55 ms | 1403 KiB | 19 Q