3v4l.org

run code in 300+ 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 );

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).

VersionSystem time (s)User time (s)Memory (MiB)
7.4.100.0442.15616.65
7.4.90.0362.17616.73
7.4.80.0262.33116.53
7.3.220.0621.96516.67
7.3.210.0852.20216.74
7.2.330.0292.25216.82
7.2.120.0931.47014.75
7.2.110.1891.40814.75
7.2.100.1361.53414.94
7.2.90.1211.50315.06
7.2.80.0831.67614.73
7.2.70.0331.48515.17
7.2.60.0231.66214.93
7.2.50.0361.53015.07
7.2.40.0331.53615.08
7.2.30.0301.46915.14
7.2.20.0431.56415.11
7.2.10.0272.01215.07
7.2.00.0301.50015.17
7.1.240.1091.79414.04
7.1.230.1362.17614.23
7.1.220.2052.00314.16
7.1.210.0461.86013.98
7.1.200.1132.03614.11
7.1.190.0541.92413.87
7.1.180.0431.88913.74
7.1.170.0482.18013.88
7.1.160.0301.96413.86
7.1.150.0272.09814.05
7.1.140.0362.02714.24
7.1.130.0301.98913.98
7.1.120.0331.99413.91
7.1.110.0331.91213.86
7.1.100.0331.85314.00
7.1.90.0372.06114.05
7.1.80.0482.39214.08
7.1.70.0392.42414.07
7.1.60.0401.86413.75
7.1.50.0301.84013.79
7.1.40.0272.13213.93
7.1.30.0412.35313.84
7.1.20.0362.03814.11
7.1.10.0462.35413.80
7.1.00.0432.06813.98
5.6.380.0202.42814.81

preferences:
23.37 ms | 401 KiB | 5 Q