3v4l.org

run code in 300+ PHP versions simultaneously
<?php $urls = [ 'absolute' => 'https://stackoverflow.com/questions/20248666/in-this-case-which-is-better-in-matching-regular-expression-or-parse-url', 'relative' => '/questions/20248666/in-this-case-which-is-better-in-matching-regular-expression-or-parse-url', 'absolute-with-query' => 'https://stackoverflow.com/questions/20248666/in-this-case-which-is-better-in-matching-regular-expression-or-parse-url?r=https://3v4l.org', 'relative-with-query' => '/questions/20248666/in-this-case-which-is-better-in-matching-regular-expression-or-parse-url?r=https://3v4l.org', ]; $parseTester = function ($url) { $urlComponents = parse_url($url, PHP_URL_SCHEME); return strncmp($url, '//', 2) && empty($urlComponents); }; $regexpTester = function ($url) { return preg_match('@^((\w+):)?//@', $url); }; $strposTester = function ($url) { return strpos($url, 'https://') !== 0 || strpos($url, 'http://') !== 0 || strpos($url, '//') !== 0; }; $strposAlternativeTester = function ($url) { if (strncmp($url, '//', 2) === 0) { return false; } $pos = strpos($url, '://'); if ($pos === false) { return true; } $queryPos = strpos($url, '?'); return $queryPos === false || $pos < $queryPos; }; $test = function ($testerName, $callback) use ($urls) { foreach ($urls as $scenario => $url) { $time = microtime(true); for ($i = 0; $i < 1000000; $i++) { $callback($url); } echo "$testerName-$scenario: ", number_format(microtime(true) - $time, 10), "\n"; } echo "\n"; }; $test('parseTester', $parseTester); $test('regexpTester', $regexpTester); $test('strposTester', $strposTester); $test('strposAlternativeTester', $strposAlternativeTester);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vb0rJ
function name:  (null)
number of ops:  29
compiled vars:  !0 = $urls, !1 = $parseTester, !2 = $regexpTester, !3 = $strposTester, !4 = $strposAlternativeTester, !5 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        DECLARE_LAMBDA_FUNCTION                          ~7      [0]
          2        ASSIGN                                                   !1, ~7
   15     3        DECLARE_LAMBDA_FUNCTION                          ~9      [1]
          4        ASSIGN                                                   !2, ~9
   19     5        DECLARE_LAMBDA_FUNCTION                          ~11     [2]
          6        ASSIGN                                                   !3, ~11
   25     7        DECLARE_LAMBDA_FUNCTION                          ~13     [3]
          8        ASSIGN                                                   !4, ~13
   37     9        DECLARE_LAMBDA_FUNCTION                          ~15     [4]
         10        BIND_LEXICAL                                             ~15, !0
         11        ASSIGN                                                   !5, ~15
   49    12        INIT_DYNAMIC_CALL                                        !5
         13        SEND_VAL_EX                                              'parseTester'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
   50    16        INIT_DYNAMIC_CALL                                        !5
         17        SEND_VAL_EX                                              'regexpTester'
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0          
   51    20        INIT_DYNAMIC_CALL                                        !5
         21        SEND_VAL_EX                                              'strposTester'
         22        SEND_VAR_EX                                              !3
         23        DO_FCALL                                      0          
   52    24        INIT_DYNAMIC_CALL                                        !5
         25        SEND_VAL_EX                                              'strposAlternativeTester'
         26        SEND_VAR_EX                                              !4
         27        DO_FCALL                                      0          
         28      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/Vb0rJ
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $url, !1 = $urlComponents
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'parse_url'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        DO_ICALL                                         $2      
          5        ASSIGN                                                   !1, $2
   12     6        INIT_FCALL                                               'strncmp'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 '%2F%2F'
          9        SEND_VAL                                                 2
         10        DO_ICALL                                         $4      
         11      > JMPZ_EX                                          ~5      $4, ->14
         12    >   ISSET_ISEMPTY_CV                                 ~6      !1
         13        BOOL                                             ~5      ~6
         14    > > RETURN                                                   ~5
   13    15*     > 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/Vb0rJ
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%40%5E%28%28%5Cw%2B%29%3A%29%3F%2F%2F%40'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   17     6*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 13
filename:       /in/Vb0rJ
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'strpos'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'https%3A%2F%2F'
          4        DO_ICALL                                         $1      
          5        IS_NOT_IDENTICAL                                 ~2      $1, 0
          6      > JMPNZ_EX                                         ~2      ~2, ->13
   21     7    >   INIT_FCALL                                               'strpos'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 'http%3A%2F%2F'
         10        DO_ICALL                                         $3      
         11        IS_NOT_IDENTICAL                                 ~4      $3, 0
         12        BOOL                                             ~2      ~4
         13    > > JMPNZ_EX                                         ~2      ~2, ->20
   22    14    >   INIT_FCALL                                               'strpos'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 '%2F%2F'
         17        DO_ICALL                                         $5      
         18        IS_NOT_IDENTICAL                                 ~6      $5, 0
         19        BOOL                                             ~2      ~6
         20    > > RETURN                                                   ~2
   23    21*     > RETURN                                                   null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 47) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/Vb0rJ
function name:  {closure}
number of ops:  28
compiled vars:  !0 = $url, !1 = $pos, !2 = $queryPos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'strncmp'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%2F%2F'
          4        SEND_VAL                                                 2
          5        DO_ICALL                                         $3      
          6        IS_IDENTICAL                                             $3, 0
          7      > JMPZ                                                     ~4, ->9
   27     8    > > RETURN                                                   <false>
   29     9    >   INIT_FCALL                                               'strpos'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 '%3A%2F%2F'
         12        DO_ICALL                                         $5      
         13        ASSIGN                                                   !1, $5
   30    14        TYPE_CHECK                                    4          !1
         15      > JMPZ                                                     ~7, ->17
   31    16    > > RETURN                                                   <true>
   33    17    >   INIT_FCALL                                               'strpos'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 '%3F'
         20        DO_ICALL                                         $8      
         21        ASSIGN                                                   !2, $8
   34    22        TYPE_CHECK                                    4  ~10     !2
         23      > JMPNZ_EX                                         ~10     ~10, ->26
         24    >   IS_SMALLER                                       ~11     !1, !2
         25        BOOL                                             ~10     ~11
         26    > > RETURN                                                   ~10
   35    27*     > RETURN                                                   null

End of Dynamic Function 3

Dynamic Function 4
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 34
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 34
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 12
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 12
Branch analysis from position: 18
Branch analysis from position: 12
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/Vb0rJ
function name:  {closure}
number of ops:  37
compiled vars:  !0 = $testerName, !1 = $callback, !2 = $urls, !3 = $url, !4 = $scenario, !5 = $time, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   38     3      > FE_RESET_R                                       $7      !2, ->34
          4    > > FE_FETCH_R                                       ~8      $7, !3, ->34
          5    >   ASSIGN                                                   !4, ~8
   39     6        INIT_FCALL                                               'microtime'
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !5, $10
   40    10        ASSIGN                                                   !6, 0
         11      > JMP                                                      ->16
   41    12    >   INIT_DYNAMIC_CALL                                        !1
         13        SEND_VAR_EX                                              !3
         14        DO_FCALL                                      0          
   40    15        PRE_INC                                                  !6
         16    >   IS_SMALLER                                               !6, 1000000
         17      > JMPNZ                                                    ~15, ->12
   44    18    >   ROPE_INIT                                     4  ~17     !0
         19        ROPE_ADD                                      1  ~17     ~17, '-'
         20        ROPE_ADD                                      2  ~17     ~17, !4
         21        ROPE_END                                      3  ~16     ~17, '%3A+'
         22        ECHO                                                     ~16
         23        INIT_FCALL                                               'number_format'
         24        INIT_FCALL                                               'microtime'
         25        SEND_VAL                                                 <true>
         26        DO_ICALL                                         $19     
         27        SUB                                              ~20     $19, !5
         28        SEND_VAL                                                 ~20
         29        SEND_VAL                                                 10
         30        DO_ICALL                                         $21     
         31        ECHO                                                     $21
         32        ECHO                                                     '%0A'
   38    33      > JMP                                                      ->4
         34    >   FE_FREE                                                  $7
   46    35        ECHO                                                     '%0A'
   47    36      > RETURN                                                   null

End of Dynamic Function 4

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
123.8 ms | 1018 KiB | 19 Q