3v4l.org

run code in 500+ PHP versions simultaneously
<?php function wp_is_stream( $path ) { if ( false === strpos( $path, '://' ) ) { // $path isn't a stream return false; } $wrappers = stream_get_wrappers(); $wrappers = array_map( 'preg_quote', $wrappers ); $wrappers_re = '(' . join( '|', $wrappers ) . ')'; return preg_match( "!^$wrappers_re://!", $path ) === 1; } function wp_is_stream2( $path ) { $scheme_separator = strpos( $path, '://' ); if ( false === $scheme_separator ) { // $path isn't a stream return false; } $stream = substr( $path, 0, $scheme_separator ); return in_array( $stream, stream_get_wrappers(), true ); } print( "Testing:\n" ); $tests = [ 'test', 'php://test', 'http://test', 'unknown://test', '://', 'unknown://php://test', ]; foreach ( $tests as $test ) { printf( "%-20s - wp_is_stream() => %-5s - wp_is_stream2() => %s\n", $test, wp_is_stream( $test ) ? 'true' : 'false', wp_is_stream2( $test ) ? 'true' : 'false' ); } $test_stream = 'php://test/stream'; $iterations = 1000000; $wp_start = microtime( true ); for( $i = 0; $i < $iterations; $i++ ) { $result = wp_is_stream( $test_stream ); } $wp_end = microtime( true ); $wp_start2 = microtime( true ); for( $i = 0; $i < $iterations; $i++ ) { $result = wp_is_stream2( $test_stream ); } $wp_end2 = microtime( true ); $wp_time = $wp_end - $wp_start; $wp_time2 = $wp_end2 - $wp_start2; print( "\nBenchmarking:\n" ); printf( "wp_is_stream() => %f seconds for %d iterations\n" . "wp_is_stream2() => %f seconds for %d iterations\n", $wp_time, $iterations, $wp_time2, $iterations ); printf( "Refactor improved execution time by %d percent.\n", ( $wp_time - $wp_time2 ) / $wp_time * 100 );

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 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
Branch analysis from position: 21
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 34
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 51
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 51
Branch analysis from position: 58
Branch analysis from position: 51
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 34
Branch analysis from position: 41
Branch analysis from position: 34
Branch analysis from position: 25
filename:       /in/BTHk0
function name:  (null)
number of ops:  82
compiled vars:  !0 = $tests, !1 = $test, !2 = $test_stream, !3 = $iterations, !4 = $wp_start, !5 = $i, !6 = $result, !7 = $wp_end, !8 = $wp_start2, !9 = $wp_end2, !10 = $wp_time, !11 = $wp_time2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   ECHO                                                         'Testing%3A%0A'
   31     1        ASSIGN                                                       !0, <array>
   40     2      > FE_RESET_R                                           $13     !0, ->25
          3    > > FE_FETCH_R                                                   $13, !1, ->25
   41     4    >   INIT_FCALL                                                   'printf'
   42     5        SEND_VAL                                                     '%25-20s+-+wp_is_stream%28%29+%3D%3E+%25-5s+-+wp_is_stream2%28%29+%3D%3E+%25s%0A'
   43     6        SEND_VAR                                                     !1
   44     7        INIT_FCALL                                                   'wp_is_stream'
          8        SEND_VAR                                                     !1
          9        DO_FCALL                                          0  $14     
         10      > JMPZ                                                         $14, ->13
         11    >   QM_ASSIGN                                            ~15     'true'
         12      > JMP                                                          ->14
         13    >   QM_ASSIGN                                            ~15     'false'
         14    >   SEND_VAL                                                     ~15
   45    15        INIT_FCALL                                                   'wp_is_stream2'
         16        SEND_VAR                                                     !1
         17        DO_FCALL                                          0  $16     
         18      > JMPZ                                                         $16, ->21
         19    >   QM_ASSIGN                                            ~17     'true'
         20      > JMP                                                          ->22
         21    >   QM_ASSIGN                                            ~17     'false'
         22    >   SEND_VAL                                                     ~17
   41    23        DO_ICALL                                                     
   40    24      > JMP                                                          ->3
         25    >   FE_FREE                                                      $13
   49    26        ASSIGN                                                       !2, 'php%3A%2F%2Ftest%2Fstream'
   50    27        ASSIGN                                                       !3, 1000000
   52    28        INIT_FCALL                                                   'microtime'
         29        SEND_VAL                                                     <true>
         30        DO_ICALL                                             $21     
         31        ASSIGN                                                       !4, $21
   53    32        ASSIGN                                                       !5, 0
         33      > JMP                                                          ->39
   54    34    >   INIT_FCALL                                                   'wp_is_stream'
         35        SEND_VAR                                                     !2
         36        DO_FCALL                                          0  $24     
         37        ASSIGN                                                       !6, $24
   53    38        PRE_INC                                                      !5
         39    >   IS_SMALLER                                                   !5, !3
         40      > JMPNZ                                                        ~27, ->34
   56    41    >   INIT_FCALL                                                   'microtime'
         42        SEND_VAL                                                     <true>
         43        DO_ICALL                                             $28     
         44        ASSIGN                                                       !7, $28
   58    45        INIT_FCALL                                                   'microtime'
         46        SEND_VAL                                                     <true>
         47        DO_ICALL                                             $30     
         48        ASSIGN                                                       !8, $30
   59    49        ASSIGN                                                       !5, 0
         50      > JMP                                                          ->56
   60    51    >   INIT_FCALL                                                   'wp_is_stream2'
         52        SEND_VAR                                                     !2
         53        DO_FCALL                                          0  $33     
         54        ASSIGN                                                       !6, $33
   59    55        PRE_INC                                                      !5
         56    >   IS_SMALLER                                                   !5, !3
         57      > JMPNZ                                                        ~36, ->51
   62    58    >   INIT_FCALL                                                   'microtime'
         59        SEND_VAL                                                     <true>
         60        DO_ICALL                                             $37     
         61        ASSIGN                                                       !9, $37
   64    62        SUB                                                  ~39     !7, !4
         63        ASSIGN                                                       !10, ~39
   65    64        SUB                                                  ~41     !9, !8
         65        ASSIGN                                                       !11, ~41
   67    66        ECHO                                                         '%0ABenchmarking%3A%0A'
   68    67        INIT_FCALL                                                   'printf'
   70    68        SEND_VAL                                                     'wp_is_stream%28%29++%3D%3E+%25f+seconds+for+%25d+iterations%0Awp_is_stream2%28%29+%3D%3E+%25f+seconds+for+%25d+iterations%0A'
   71    69        SEND_VAR                                                     !10
   72    70        SEND_VAR                                                     !3
   73    71        SEND_VAR                                                     !11
   74    72        SEND_VAR                                                     !3
   68    73        DO_ICALL                                                     
   76    74        INIT_FCALL                                                   'printf'
   77    75        SEND_VAL                                                     'Refactor+improved+execution+time+by+%25d+percent.%0A'
   78    76        SUB                                                  ~44     !10, !11
         77        DIV                                                  ~45     ~44, !10
         78        MUL                                                  ~46     ~45, 100
         79        SEND_VAL                                                     ~46
   76    80        DO_ICALL                                                     
   79    81      > RETURN                                                       1

Function wp_is_stream:
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/BTHk0
function name:  wp_is_stream
number of ops:  27
compiled vars:  !0 = $path, !1 = $wrappers, !2 = $wrappers_re
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        FRAMELESS_ICALL_2                strpos              ~3      !0, '%3A%2F%2F'
          2        TYPE_CHECK                                        4          ~3
          3      > JMPZ                                                         ~4, ->5
    6     4    > > RETURN                                                       <false>
    9     5    >   INIT_FCALL                                                   'stream_get_wrappers'
          6        DO_ICALL                                             $5      
          7        ASSIGN                                                       !1, $5
   10     8        INIT_FCALL                                                   'array_map'
          9        SEND_VAL                                                     'preg_quote'
         10        SEND_VAR                                                     !1
         11        DO_ICALL                                             $7      
         12        ASSIGN                                                       !1, $7
   11    13        INIT_FCALL                                                   'join'
         14        SEND_VAL                                                     '%7C'
         15        SEND_VAR                                                     !1
         16        DO_ICALL                                             $9      
         17        CONCAT                                               ~10     '%28', $9
         18        CONCAT                                               ~11     ~10, '%29'
         19        ASSIGN                                                       !2, ~11
   13    20        ROPE_INIT                                         3  ~14     '%21%5E'
         21        ROPE_ADD                                          1  ~14     ~14, !2
         22        ROPE_END                                          2  ~13     ~14, '%3A%2F%2F%21'
         23        FRAMELESS_ICALL_2                preg_match          ~16     ~13, !0
         24        IS_IDENTICAL                                         ~17     ~16, 1
         25      > RETURN                                                       ~17
   14    26*     > RETURN                                                       null

End of function wp_is_stream

Function wp_is_stream2:
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 = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BTHk0
function name:  wp_is_stream2
number of ops:  15
compiled vars:  !0 = $path, !1 = $scheme_separator, !2 = $stream
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV                                                 !0      
   17     1        FRAMELESS_ICALL_2                strpos              ~3      !0, '%3A%2F%2F'
          2        ASSIGN                                                       !1, ~3
   19     3        TYPE_CHECK                                        4          !1
          4      > JMPZ                                                         ~5, ->6
   21     5    > > RETURN                                                       <false>
   24     6    >   FRAMELESS_ICALL_3                substr              ~6      !0, 0
          7        OP_DATA                                                      !1
          8        ASSIGN                                                       !2, ~6
   26     9        INIT_FCALL                                                   'stream_get_wrappers'
         10        DO_ICALL                                             $8      
         11        FRAMELESS_ICALL_3                in_array            ~9      !2, $8
         12        OP_DATA                                                      <true>
         13      > RETURN                                                       ~9
   27    14*     > RETURN                                                       null

End of function wp_is_stream2

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.16 ms | 1322 KiB | 22 Q