3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = str_repeat("a\u{0308}bc", 1000); echo '$str = ', $str, "\n"; function test($name, $test) { $t = microtime(true); for ($i = 0; $i < 1000; ++$i) { $test(); } echo sprintf('%.6f', (microtime(true) - $t)), 's ', $name, "\n"; } foreach (["a\u{0308}bc", 'abc', str_repeat("a\u{0308}bc", 20).'a'] as $prefix) { echo "\n", '$prefix = ', $prefix, "\n"; test('grapheme_strpos', function () use ($str, $prefix) { return 0 === grapheme_strpos($str, $prefix); }); test('grapheme_substr', function () use ($str, $prefix) { return $prefix === grapheme_substr($str, 0, grapheme_strlen($prefix)); }); test('grapheme_extract', function () use ($str, $prefix) { return $prefix === grapheme_extract($str, strlen($prefix), GRAPHEME_EXTR_MAXBYTES); }); }
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/gd91p
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                                                 'a%CC%88bc'
          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      'a%CC%88bc'
          9        ADD_ARRAY_ELEMENT                                ~4      'abc'
         10        INIT_FCALL                                               'str_repeat'
         11        SEND_VAL                                                 'a%CC%88bc'
         12        SEND_VAL                                                 20
         13        DO_ICALL                                         $5      
         14        CONCAT                                           ~6      $5, 'a'
         15        ADD_ARRAY_ELEMENT                                ~4      ~6
         16      > FE_RESET_R                                       $7      ~4, ->44
         17    > > FE_FETCH_R                                               $7, !1, ->44
   18    18    >   ECHO                                                     '%0A'
         19        ECHO                                                     '%24prefix+%3D+'
         20        ECHO                                                     !1
         21        ECHO                                                     '%0A'
   20    22        INIT_FCALL                                               'test'
         23        SEND_VAL                                                 'grapheme_strpos'
         24        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
         25        BIND_LEXICAL                                             ~8, !0
         26        BIND_LEXICAL                                             ~8, !1
   22    27        SEND_VAL                                                 ~8
   20    28        DO_FCALL                                      0          
   24    29        INIT_FCALL                                               'test'
         30        SEND_VAL                                                 'grapheme_substr'
         31        DECLARE_LAMBDA_FUNCTION                          ~10     [1]
         32        BIND_LEXICAL                                             ~10, !0
         33        BIND_LEXICAL                                             ~10, !1
   26    34        SEND_VAL                                                 ~10
   24    35        DO_FCALL                                      0          
   28    36        INIT_FCALL                                               'test'
         37        SEND_VAL                                                 'grapheme_extract'
         38        DECLARE_LAMBDA_FUNCTION                          ~12     [2]
         39        BIND_LEXICAL                                             ~12, !0
         40        BIND_LEXICAL                                             ~12, !1
   30    41        SEND_VAL                                                 ~12
   28    42        DO_FCALL                                      0          
   17    43      > JMP                                                      ->17
         44    >   FE_FREE                                                  $7
   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/gd91p
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_BY_NAME                                       'grapheme_strpos'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $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/gd91p
function name:  {closure}
number of ops:  13
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_BY_NAME                                       'grapheme_substr'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAL_EX                                              0
          5        INIT_FCALL_BY_NAME                                       'grapheme_strlen'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $2      
          8        SEND_VAR_NO_REF_EX                                       $2
          9        DO_FCALL                                      0  $3      
         10        IS_IDENTICAL                                     ~4      !1, $3
         11      > RETURN                                                   ~4
   26    12*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gd91p
function name:  {closure}
number of ops:  12
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        INIT_FCALL_BY_NAME                                       'grapheme_extract'
          3        SEND_VAR_EX                                              !0
          4        STRLEN                                           ~2      !1
          5        SEND_VAL_EX                                              ~2
          6        FETCH_CONSTANT                                   ~3      'GRAPHEME_EXTR_MAXBYTES'
          7        SEND_VAL_EX                                              ~3
          8        DO_FCALL                                      0  $4      
          9        IS_IDENTICAL                                     ~5      !1, $4
         10      > RETURN                                                   ~5
   30    11*     > 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/gd91p
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, 1000
         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:
144.69 ms | 998 KiB | 19 Q