Skip to content

Instantly share code, notes, and snippets.

@typhonius
Created August 2, 2013 14:31
Show Gist options
  • Save typhonius/6140308 to your computer and use it in GitHub Desktop.
Save typhonius/6140308 to your computer and use it in GitHub Desktop.
<?php
# Memcache
print "Memcache API\n";
$conf['cache_backends'][] = './sites/all/modules/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
bench_it();
#Memcache Storage
print "Memcache Storage\n";
$conf['cache_backends'][] = 'sites/all/modules/memcache_storage/memcache_storage.inc';
$conf['cache_default_class'] = 'MemcacheStorage';
bench_it();
function bench_it() {
$iterations = 25000;
timer_start('set');
for ($i = 0; $i < $iterations; $i++) {
cache_set("test-$i", 1, 'cache', CACHE_PERMANENT);
}
timer_stop('set');
timer_start('get');
for ($i = 0; $i < $iterations; $i++) {
$cache = cache_get("test-$i");
if (!isset($cache->data) || $cache->data != 1) exit("cache_get() failed.");
}
timer_stop('get');
timer_start('clear');
for ($i = 0; $i < $iterations; $i++) {
_cache_get_object('cache')->clear("test-$i", FALSE);
}
timer_stop('clear');
unset($GLOBALS['timers']['page']);
foreach ($GLOBALS['timers'] as $name => $timer) {
if ($name == 'get' || $name == 'set') {
$timer['time'] /= $iterations;
}
print sprintf("%s:\t\t%.4fms\n", str_pad($name, 12), $timer['time']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment