@ 2018-11-24T14:18:25Z <?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
);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Abusive script This script was stopped while abusing our resources
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.4.10 0.044 2.156 16.65 7.4.9 0.036 2.176 16.73 7.4.8 0.026 2.331 16.53 7.3.22 0.062 1.965 16.67 7.3.21 0.085 2.202 16.74 7.2.33 0.029 2.252 16.82 7.2.12 0.093 1.470 14.75 7.2.11 0.189 1.408 14.75 7.2.10 0.136 1.534 14.94 7.2.9 0.121 1.503 15.06 7.2.8 0.083 1.676 14.73 7.2.7 0.033 1.485 15.17 7.2.6 0.023 1.662 14.93 7.2.5 0.036 1.530 15.07 7.2.4 0.033 1.536 15.08 7.2.3 0.030 1.469 15.14 7.2.2 0.043 1.564 15.11 7.2.1 0.027 2.012 15.07 7.2.0 0.030 1.500 15.17 7.1.24 0.109 1.794 14.04 7.1.23 0.136 2.176 14.23 7.1.22 0.205 2.003 14.16 7.1.21 0.046 1.860 13.98 7.1.20 0.113 2.036 14.11 7.1.19 0.054 1.924 13.87 7.1.18 0.043 1.889 13.74 7.1.17 0.048 2.180 13.88 7.1.16 0.030 1.964 13.86 7.1.15 0.027 2.098 14.05 7.1.14 0.036 2.027 14.24 7.1.13 0.030 1.989 13.98 7.1.12 0.033 1.994 13.91 7.1.11 0.033 1.912 13.86 7.1.10 0.033 1.853 14.00 7.1.9 0.037 2.061 14.05 7.1.8 0.048 2.392 14.08 7.1.7 0.039 2.424 14.07 7.1.6 0.040 1.864 13.75 7.1.5 0.030 1.840 13.79 7.1.4 0.027 2.132 13.93 7.1.3 0.041 2.353 13.84 7.1.2 0.036 2.038 14.11 7.1.1 0.046 2.354 13.80 7.1.0 0.043 2.068 13.98 5.6.38 0.020 2.428 14.81
preferences:dark mode live preview
29.24 ms | 403 KiB | 5 Q