Skip to content

Instantly share code, notes, and snippets.

@peterwilsoncc
Created January 30, 2023 00:30
Show Gist options
  • Save peterwilsoncc/580c8bea21f1cddfbd8ff151d8718024 to your computer and use it in GitHub Desktop.
Save peterwilsoncc/580c8bea21f1cddfbd8ff151d8718024 to your computer and use it in GitHub Desktop.
<?php
namespace PWCC\Nope\PreOptionTesting;
const RUNS = 10000;
// return;
add_action( 'init', function(){
$run_time = 0;
get_option( 'siteurl' );
for( $i = RUNS; $i > 0; $i-- ) {
$time_start = microtime( true );
get_option( 'siteurl' );
$run_time += microtime( true ) - $time_start;
}
echo '<pre>';
echo 'option_siteurl: ' . ( $run_time / RUNS ) . ' seconds' . PHP_EOL;
echo '</pre>';
}, 10 );
add_action( 'init', function(){
remove_filter( 'option_home', '_config_wp_home' );
remove_filter( 'option_siteurl', '_config_wp_siteurl' );
add_filter( 'pre_option_home', '_config_wp_home' );
add_filter( 'pre_option_siteurl', '_config_wp_siteurl' );
$run_time = 0;
get_option( 'siteurl' );
for( $i = RUNS; $i > 0; $i-- ) {
$time_start = microtime( true );
get_option( 'siteurl' );
$run_time += microtime( true ) - $time_start;
}
echo '<pre>';
echo 'pre_option_siteurl: ' . ( $run_time / RUNS ) . ' seconds' . PHP_EOL;
echo '</pre>';
}, 20 );
add_action( 'init', function(){
exit;
}, 30 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment