3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Run a million cycles for the profile averages. $cycles = 1000000; // Setup. define( 'WP_PLUGIN_DIR', 'absolute/path/to/the/plugins/dir' ); $plugin = 'plugin/plugin.php'; $plugins_dir = trailingslashit( WP_PLUGIN_DIR ); $plugins_dir_strlen = strlen( $plugins_dir ); // Polyfills. function trailingslashit( $value ) { return untrailingslashit( $value ) . '/'; } function untrailingslashit( $value ) { return rtrim( $value, '/\\' ); } // Test str_replace(). $start_time = microtime( true ); for ( $i = 1; $i <= $cycles; $i++ ) { $plugin_file = str_replace( $plugins_dir, '', $plugin ); } $end_time = microtime( true ); $total_time = ( $end_time - $start_time ) * 1000000.0; printf( "Ran str_replace() in %s microseconds average\n", number_format( $total_time / $cycles, 4 ) ); // Test substr(). $start_time = microtime( true ); for ( $i = 1; $i <= $cycles; $i++ ) { $plugin_file = substr( $plugin, $plugins_dir_strlen ); } $end_time = microtime( true ); $total_time = ( $end_time - $start_time ) * 1000000.0; printf( "Ran substr() in %s microseconds average\n", number_format( $total_time / $cycles, 4 ) );

preferences:
25.08 ms | 410 KiB | 5 Q