3v4l.org

run code in 500+ PHP versions simultaneously
<?php if ( ! function_exists( 'str_starts_with' ) ) { function str_starts_with( $haystack, $needle ) { if ( '' === $needle ) { return true; } return 0 === strpos( $haystack, $needle ); } } $string = 'abcdefghijklmnopqrstuvwxyz'; $start = hrtime(true); for ( $i = 0; $i < 1000000; $i++ ) { $result1 = str_starts_with( $string, 'abc' ); $result2 = str_starts_with( $string, 'abd' ); } $end = hrtime(true); $str_starts_with_time = $end - $start; $start = hrtime(true); for ( $i = 0; $i < 1000000; $i++ ) { $result1 = 0 === strpos( $string, 'abc' ); $result2 = 0 === strpos( $string, 'abd' ); } $end = hrtime(true); $strpos_time = $end - $start; echo 'str_starts_with: ' . $str_starts_with_time . PHP_EOL; echo 'strpos: ' . $strpos_time . PHP_EOL; // echo which function is faster if ( $str_starts_with_time < $strpos_time ) { echo 'str_starts_with is faster' . PHP_EOL; } else { echo 'strpos is faster' . PHP_EOL; }
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 = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 13
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 32
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 32
Branch analysis from position: 41
Branch analysis from position: 32
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 13
Branch analysis from position: 20
Branch analysis from position: 13
Branch analysis from position: 6
filename:       /in/dUbZ9
function name:  (null)
number of ops:  59
compiled vars:  !0 = $string, !1 = $start, !2 = $i, !3 = $result1, !4 = $result2, !5 = $end, !6 = $str_starts_with_time, !7 = $strpos_time
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'function_exists'
          1        SEND_VAL                                                     'str_starts_with'
          2        DO_ICALL                                             $8      
          3        BOOL_NOT                                             ~9      $8
          4      > JMPZ                                                         ~9, ->6
    4     5    >   DECLARE_FUNCTION                                             'str_starts_with'
   12     6    >   ASSIGN                                                       !0, 'abcdefghijklmnopqrstuvwxyz'
   14     7        INIT_FCALL                                                   'hrtime'
          8        SEND_VAL                                                     <true>
          9        DO_ICALL                                             $11     
         10        ASSIGN                                                       !1, $11
   16    11        ASSIGN                                                       !2, 0
         12      > JMP                                                          ->18
   17    13    >   FRAMELESS_ICALL_2                str_starts_with      ~14     !0, 'abc'
         14        ASSIGN                                                       !3, ~14
   18    15        FRAMELESS_ICALL_2                str_starts_with      ~16     !0, 'abd'
         16        ASSIGN                                                       !4, ~16
   16    17        PRE_INC                                                      !2
         18    >   IS_SMALLER                                                   !2, 1000000
         19      > JMPNZ                                                        ~19, ->13
   21    20    >   INIT_FCALL                                                   'hrtime'
         21        SEND_VAL                                                     <true>
         22        DO_ICALL                                             $20     
         23        ASSIGN                                                       !5, $20
   23    24        SUB                                                  ~22     !5, !1
         25        ASSIGN                                                       !6, ~22
   25    26        INIT_FCALL                                                   'hrtime'
         27        SEND_VAL                                                     <true>
         28        DO_ICALL                                             $24     
         29        ASSIGN                                                       !1, $24
   27    30        ASSIGN                                                       !2, 0
         31      > JMP                                                          ->39
   28    32    >   FRAMELESS_ICALL_2                strpos              ~27     !0, 'abc'
         33        IS_IDENTICAL                                         ~28     ~27, 0
         34        ASSIGN                                                       !3, ~28
   29    35        FRAMELESS_ICALL_2                strpos              ~30     !0, 'abd'
         36        IS_IDENTICAL                                         ~31     ~30, 0
         37        ASSIGN                                                       !4, ~31
   27    38        PRE_INC                                                      !2
         39    >   IS_SMALLER                                                   !2, 1000000
         40      > JMPNZ                                                        ~34, ->32
   32    41    >   INIT_FCALL                                                   'hrtime'
         42        SEND_VAL                                                     <true>
         43        DO_ICALL                                             $35     
         44        ASSIGN                                                       !5, $35
   34    45        SUB                                                  ~37     !5, !1
         46        ASSIGN                                                       !7, ~37
   36    47        CONCAT                                               ~39     'str_starts_with%3A+', !6
         48        CONCAT                                               ~40     ~39, '%0A'
         49        ECHO                                                         ~40
   37    50        CONCAT                                               ~41     'strpos%3A+', !7
         51        CONCAT                                               ~42     ~41, '%0A'
         52        ECHO                                                         ~42
   40    53        IS_SMALLER                                                   !6, !7
         54      > JMPZ                                                         ~43, ->57
   41    55    >   ECHO                                                         'str_starts_with+is+faster%0A'
   40    56      > JMP                                                          ->58
   43    57    >   ECHO                                                         'strpos+is+faster%0A'
   44    58    > > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
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/dUbZ9
function name:  str_starts_with
number of ops:  9
compiled vars:  !0 = $haystack, !1 = $needle
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        IS_IDENTICAL                                                 !1, ''
          3      > JMPZ                                                         ~2, ->5
    6     4    > > RETURN                                                       <true>
    8     5    >   FRAMELESS_ICALL_2                strpos              ~3      !0, !1
          6        IS_IDENTICAL                                         ~4      ~3, 0
          7      > RETURN                                                       ~4
    9     8*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
179.2 ms | 1744 KiB | 15 Q