Skip to content

Instantly share code, notes, and snippets.

@jdalsem
Created November 18, 2016 12:21
Show Gist options
  • Save jdalsem/43dfa6f58db1046e32e9aeabf232fff5 to your computer and use it in GitHub Desktop.
Save jdalsem/43dfa6f58db1046e32e9aeabf232fff5 to your computer and use it in GitHub Desktop.
Test script for benchmark elgg_get_entities functions
<?php
set_time_limit(0);
$starttime = microtime(true);
echo '<h1>Benchmark</h1><br />';
$options = [
'limit' => false,
];
$total = 0;
$counter = _elgg_db_get_query_counter();
$batch = new \ElggBatch('elgg_get_entities', $options);
foreach ($batch as $entity) {
$temp = $entity->icontime; // this triggers metadata getAll
$total++;
}
$end = round(microtime(true) - $starttime, 4);
echo "Batched $total entities using ege with {$counter->getDelta()} queries in {$end}s<br />";
$avg = round($end / $total, 4);
echo "Average = {$avg}s per entity<br /><br />";
$total = 0;
$starttime = microtime(true);
$counter = _elgg_db_get_query_counter();
$batch = new \ElggBatch('elgg_get_entities', $options);
foreach ($batch as $entity) {
$md = elgg_get_metadata(['guid' => $entity->guid]);
$total++;
}
$end = round(microtime(true) - $starttime, 4);
echo "Batched $total entities using ege with {$counter->getDelta()} queries with elgg_get_metadata in {$end}s<br />";
$avg = round($end / $total, 4);
echo "Average = {$avg}s per entity<br /><br />";
// blogs
$total = 0;
$starttime = microtime(true);
$counter = _elgg_db_get_query_counter();
$blog_options = $options;
$batch = new \ElggBatch('elgg_get_entities_from_metadata', $blog_options);
foreach ($batch as $entity) {
// $md = elgg_get_metadata(['guid' => $entity->guid]);
$total++;
}
$end = round(microtime(true) - $starttime, 4);
echo "Batched $total entities using egef_metadata (without options) with {$counter->getDelta()} queries in {$end}s<br />";
$avg = round($end / $total, 4);
echo "Average = {$avg}s per entity<br /><br />";
$total = 0;
$starttime = microtime(true);
$counter = _elgg_db_get_query_counter();
$blog_options['metadata_name_value_pairs'] = [
'status' => 'published',
];
$batch = new \ElggBatch('elgg_get_entities_from_metadata', $blog_options);
foreach ($batch as $entity) {
// $md = elgg_get_metadata(['guid' => $entity->guid]);
$total++;
}
$end = round(microtime(true) - $starttime, 4);
echo "Batched $total entities using egef_metadata with {$counter->getDelta()} queries in {$end}s<br />";
$avg = round($end / $total, 4);
echo "Average = {$avg}s per entity<br /><br />";
$total = 0;
$starttime = microtime(true);
$counter = _elgg_db_get_query_counter();
$batch = new \ElggBatch('elgg_get_entities_from_metadata', $blog_options);
foreach ($batch as $entity) {
$md = elgg_get_metadata(['guid' => $entity->guid]);
$total++;
}
$end = round(microtime(true) - $starttime, 4);
echo "Batched $total entities using egef_metadata with {$counter->getDelta()} queries with elgg_get_metadata in {$end}s<br />";
$avg = round($end / $total, 4);
echo "Average = {$avg}s per entity<br /><br />";
// likes from annotations
$total = 0;
$starttime = microtime(true);
$like_options = $options;
$counter = _elgg_db_get_query_counter();
$batch = new \ElggBatch('elgg_get_entities_from_annotations', $like_options);
foreach ($batch as $entity) {
$total++;
}
$end = round(microtime(true) - $starttime, 4);
echo "Batched $total entities using egef_annotations (without options) with {$counter->getDelta()} queries in {$end}s<br />";
$avg = round($end / $total, 4);
echo "Average = {$avg}s per entity<br /><br />";
$total = 0;
$starttime = microtime(true);
$like_options['annotation_name_value_pairs'] = [
'likes' => 'likes',
];
$counter = _elgg_db_get_query_counter();
$batch = new \ElggBatch('elgg_get_entities_from_annotations', $like_options);
foreach ($batch as $entity) {
$total++;
}
$end = round(microtime(true) - $starttime, 4);
echo "Batched $total entities using egef_annotations with {$counter->getDelta()} queries in {$end}s<br />";
$avg = round($end / $total, 4);
echo "Average = {$avg}s per entity<br /><br />";
$total = 0;
$starttime = microtime(true);
$counter = _elgg_db_get_query_counter();
$batch = new \ElggBatch('elgg_get_entities_from_annotations', $like_options);
foreach ($batch as $entity) {
$md = elgg_get_metadata(['guid' => $entity->guid]);
$total++;
}
$end = round(microtime(true) - $starttime, 4);
echo "Batched $total entities using egef_annotations with {$counter->getDelta()} queries with elgg_get_metadata in {$end}s<br />";
$avg = round($end / $total, 4);
echo "Average = {$avg}s per entity<br /><br />";
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment