3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = str_repeat('abc', 1000); echo '$str = ', $str, "\n"; function test($name, $test) { $t = microtime(true); for ($i = 0; $i < 100000; ++$i) { $test(); } echo sprintf('%.6f', (microtime(true) - $t)), 's ', $name, "\n"; } foreach (['abc', 'abb', 'bbc', str_repeat('b', 100)] as $prefix) { echo "\n", '$prefix = ', $prefix, "\n"; test('strpos', function () use ($str, $prefix) { return 0 === strpos($str, $prefix); }); test('strncmp', function () use ($str, $prefix) { return 0 === strncmp($str, $prefix, strlen($prefix)); }); test('[0] + strncmp', function () use ($str, $prefix) { return $prefix[0] === $str[0] && 0 === strncmp($str, $prefix, strlen($prefix)); }); }

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 44
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 44
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/7TkbQ
function name:  (null)
number of ops:  46
compiled vars:  !0 = $str, !1 = $prefix
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'str_repeat'
          1        SEND_VAL                                                 'abc'
          2        SEND_VAL                                                 1000
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
    5     5        ECHO                                                     '%24str+%3D+'
          6        ECHO                                                     !0
          7        ECHO                                                     '%0A'
   17     8        INIT_ARRAY                                       ~4      'abc'
          9        ADD_ARRAY_ELEMENT                                ~4      'abb'
         10        ADD_ARRAY_ELEMENT                                ~4      'bbc'
         11        INIT_FCALL                                               'str_repeat'
         12        SEND_VAL                                                 'b'
         13        SEND_VAL                                                 100
         14        DO_ICALL                                         $5      
         15        ADD_ARRAY_ELEMENT                                ~4      $5
         16      > FE_RESET_R                                       $6      ~4, ->44
         17    > > FE_FETCH_R                                               $6, !1, ->44
   18    18    >   ECHO                                                     '%0A'
         19        ECHO                                                     '%24prefix+%3D+'
         20        ECHO                                                     !1
         21        ECHO                                                     '%0A'
   20    22        INIT_FCALL                                               'test'
         23        SEND_VAL                                                 'strpos'
         24        DECLARE_LAMBDA_FUNCTION                          ~7      [0]
         25        BIND_LEXICAL                                             ~7, !0
         26        BIND_LEXICAL                                             ~7, !1
   22    27        SEND_VAL                                                 ~7
   20    28        DO_FCALL                                      0          
   24    29        INIT_FCALL                                               'test'
         30        SEND_VAL                                                 'strncmp'
         31        DECLARE_LAMBDA_FUNCTION                          ~9      [1]
         32        BIND_LEXICAL                                             ~9, !0
         33        BIND_LEXICAL                                             ~9, !1
   26    34        SEND_VAL                                                 ~9
   24    35        DO_FCALL                                      0          
   28    36        INIT_FCALL                                               'test'
         37        SEND_VAL                                                 '%5B0%5D+%2B+strncmp'
         38        DECLARE_LAMBDA_FUNCTION                          ~11     [2]
         39        BIND_LEXICAL                                             ~11, !0
         40        BIND_LEXICAL                                             ~11, !1
   30    41        SEND_VAL                                                 ~11
   28    42        DO_FCALL                                      0          
   17    43      > JMP                                                      ->17
         44    >   FE_FREE                                                  $6
   31    45      > 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/7TkbQ
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $str, !1 = $prefix
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
   21     2        INIT_FCALL                                               'strpos'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6        IS_IDENTICAL                                     ~3      $2, 0
          7      > RETURN                                                   ~3
   22     8*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7TkbQ
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $str, !1 = $prefix
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
   25     2        INIT_FCALL                                               'strncmp'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        STRLEN                                           ~2      !1
          6        SEND_VAL                                                 ~2
          7        DO_ICALL                                         $3      
          8        IS_IDENTICAL                                     ~4      $3, 0
          9      > RETURN                                                   ~4
   26    10*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/7TkbQ
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $str, !1 = $prefix
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
   29     2        FETCH_DIM_R                                      ~2      !1, 0
          3        FETCH_DIM_R                                      ~3      !0, 0
          4        IS_IDENTICAL                                     ~4      ~2, ~3
          5      > JMPZ_EX                                          ~4      ~4, ->14
          6    >   INIT_FCALL                                               'strncmp'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        STRLEN                                           ~5      !1
         10        SEND_VAL                                                 ~5
         11        DO_ICALL                                         $6      
         12        IS_IDENTICAL                                     ~7      $6, 0
         13        BOOL                                             ~4      ~7
         14    > > RETURN                                                   ~4
   30    15*     > RETURN                                                   null

End of Dynamic Function 2

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/7TkbQ
function name:  test
number of ops:  26
compiled vars:  !0 = $name, !1 = $test, !2 = $t, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_FCALL                                               'microtime'
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !2, $4
   10     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->11
   11     8    >   INIT_DYNAMIC_CALL                                        !1
          9        DO_FCALL                                      0          
   10    10        PRE_INC                                                  !3
         11    >   IS_SMALLER                                               !3, 100000
         12      > JMPNZ                                                    ~9, ->8
   14    13    >   INIT_FCALL                                               'sprintf'
         14        SEND_VAL                                                 '%25.6f'
         15        INIT_FCALL                                               'microtime'
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $10     
         18        SUB                                              ~11     $10, !2
         19        SEND_VAL                                                 ~11
         20        DO_ICALL                                         $12     
         21        ECHO                                                     $12
         22        ECHO                                                     's+'
         23        ECHO                                                     !0
         24        ECHO                                                     '%0A'
   15    25      > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.9 ms | 1442 KiB | 21 Q