<?php $num_cycles = 1000000; $src = 'path/to.a/fonts/folder/in.a/themes/some.font.woff'; $sec_to_microsec = 1000000.0; // Code implementations to benchmark. function using_explode_and_end() { global $src; $src_as_array = explode( '.', $src ); $file_type = end( $src_as_array ); } function using_pos_and_substring() { global $src; $file_type_pos = strrpos( $src, '.' ) + 1; $file_type = substr( $src, $file_type_pos ); } /** * BENCHMARK CODE */ printf( "Average microseconds running code for %s cycles:\n\n", number_format( $num_cycles, 0 ) ); // Benchmark the code with `explode` and `end` combination. $microseconds = 0; $start_time = microtime( true ); for ( $i = 1; $i <= $num_cycles; $i++ ) { using_explode_and_end(); } $end_time = microtime( true ); $microseconds += ( $end_time - $start_time ) * $sec_to_microsec; // store in microseconds. printf( "`explode` with `end`: \t\t%s μs\n", number_format( $microseconds / $num_cycles, 4 ) ); // Benchmark the code with `explode` and `end` combination. $microseconds = 0; $start_time = microtime( true ); for ( $i = 1; $i <= $num_cycles; $i++ ) { using_pos_and_substring(); } $end_time = microtime( true ); $microseconds += ( $end_time - $start_time ) * $sec_to_microsec; // store in microseconds. printf( "`strrpos` with `substr`: \t%s μs", number_format( $microseconds / $num_cycles, 4 ) );
You have javascript disabled. You will not be able to edit any code.