-
-
Save peterwilsoncc/df70e801e0ec2c8997607c0afd13b5cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add_filter( 'wp_is_large_user_count', '__return_true' ); | |
// add_filter( 'split_the_query', '__return_true' ); | |
// return; | |
function pwcc_test() { | |
global $wpdb; | |
$non_cached_ids = range( 1035, 1044 ); | |
$new = sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s) LIMIT %d", implode( ',', $non_cached_ids ), count( $non_cached_ids ) ); | |
$old = sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ); | |
$time = ['patched'=>0, 'unpatched'=>0]; | |
$queries = ['patched'=>0, 'unpatched'=>0]; | |
$tests = 10000; | |
foreach (['cached'=>true/*, 'uncached'=>false*/] as $cached => $cbool ) { | |
wp_cache_flush(); | |
$loop = $tests; | |
while( $loop > 0 ) { | |
$loop--; | |
if ( ! $cbool ) wp_cache_flush(); | |
// New Query. | |
$n = get_num_queries(); | |
$a = microtime(true); | |
$wpdb->get_results( $new ); | |
$time['patched'] = $time['patched'] + ( microtime(true) - $a ); | |
$queries['patched'] = $queries['patched'] + ( get_num_queries() - $n ); | |
// } | |
// | |
// wp_cache_flush(); | |
// $loop = $tests; | |
// while( $loop > 0 ) { | |
// $loop--; | |
// | |
// if ( ! $cbool ) wp_cache_flush(); | |
// | |
// Old Query. | |
$n = get_num_queries(); | |
$a = microtime( true ); | |
$wpdb->get_results( $old ); | |
$time['unpatched'] = $time['unpatched'] + ( microtime(true) - $a ); | |
$queries['unpatched'] = $queries['unpatched'] + ( get_num_queries() - $n ); | |
} | |
var_dump( | |
[$cached, | |
$size, | |
$time, | |
$queries] | |
); | |
$time = ['patched'=>0, 'unpatched'=>0]; | |
$queries = ['patched'=>0, 'unpatched'=>0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment