Skip to content

Instantly share code, notes, and snippets.

@MKorostoff
Created April 23, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MKorostoff/476d29bb9f6d2394cc5d to your computer and use it in GitHub Desktop.
Save MKorostoff/476d29bb9f6d2394cc5d to your computer and use it in GitHub Desktop.
<?php
for ($i=1; $i <= 10; $i++) {
$start = microtime(true);
for ($ii=0; $ii < 5000; $ii++) {
//Pick 8 random tids to search for
$tids = array();
for ($iii=0; $iii < 8; $iii++) {
$tids[] = rand(500, 1000000);
}
//Stuff the randomly selected tids into an array compatible with db_query
$args = array(
":tids" => $tids
);
//Get a ranked list of the 5 nodes which have the most matches
$query = db_query("SELECT nid
FROM taxonomy_index
WHERE tid
IN (:tids)", $args);
$results = $query->fetchAll();
$result_array = array();
foreach ($results as $result) {
$result_array[] = $result->nid;
}
arsort(array_count_values($result_array));
$result_array = array_slice($result_array, 0, 5, true);
}
print "Run $i: " . round(microtime(true) - $start, 3) . ' seconds' . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment