Skip to content

Instantly share code, notes, and snippets.

@kevinohashi
Created September 24, 2015 20:01
Show Gist options
  • Save kevinohashi/fd801b4904370541f321 to your computer and use it in GitHub Desktop.
Save kevinohashi/fd801b4904370541f321 to your computer and use it in GitHub Desktop.
WPPerformanceTester $wpdb test
function test_wordpress(){
//create dummy text to insert into database
$dummytextseed = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sollicitudin iaculis libero id pellentesque. Donec sodales nunc id lorem rutrum molestie. Duis ac ornare diam. In hac habitasse platea dictumst. Donec nec mi ipsum. Aenean dictum imperdiet erat, at lacinia mi ultrices ut. Phasellus quis nibh ornare, pulvinar dui sit amet, venenatis arcu. Suspendisse eget vehicula ligula, et placerat sapien. Cras enim erat, scelerisque sit amet tellus vel, tempor venenatis risus. In ultricies tristique ante, eu lobortis leo. Cras ullamcorper eleifend libero, quis sollicitudin massa venenatis a. Vestibulum sed pellentesque urna, nec consectetur nulla. Vestibulum sodales purus metus, non scelerisque.";
$dummytext = "";
for($x=0; $x<100; $x++){
$dummytext .= str_shuffle($dummytextseed);
}
//start timing wordpress mysql functions
$time_start = microtime(true);
global $wpdb;
$table = $wpdb->prefix . 'options';
$optionname = 'wpperformancetesterbenchmark_';
$count = 250;
for($x=0; $x<$count;$x++){
//insert
$data = array('option_name' => $optionname . $x, 'option_value' => $dummytext);
$wpdb->insert($table, $data);
//select
$select = "SELECT option_value FROM $table WHERE option_name='$optionname" . $x . "'";
$wpdb->get_var($select);
//update
$data = array('option_value' => $dummytextseed);
$where = array('option_name' => $optionname . $x);
$wpdb->update($table, $data, $where);
//delete
$where = array('option_name'=>$optionname.$x);
$wpdb->delete($table,$where);
}
$time = timer_diff($time_start);
$queries = ($count * 4) / $time;
return array('time'=>$time,'queries'=>$queries);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment