How it works:
* Records the current timestamp before running the query.
* Executes the database query using `$wpdb->get_results()`.
* Calculates the elapsed time immediately after the query completes.
* Logs the execution time to the PHP error log.
This technique is useful for:
* Identifying slow SQL queries.
* Comparing the performance of different query implementations.
* Debugging performance bottlenecks during plugin or theme development.
* Benchmarking custom database operations.
global $wpdb;
$start = microtime( true );
$results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_status = %s", 'publish' ) );
$execution_time = microtime( true ) - $start;
error_log( sprintf( 'Database query took %.5f seconds.', $execution_time ) );