Skip to content

Instantly share code, notes, and snippets.

@k-holy
Created August 3, 2011 09:47
Show Gist options
  • Save k-holy/1122279 to your computer and use it in GitHub Desktop.
Save k-holy/1122279 to your computer and use it in GitHub Desktop.
php-memcacheのてすと
<?php
$array = range(0, 10000);
$options = array_combine(
array_map(function($i) {
return sha1($i);
}, $array),
array_map(function($i) {
return crc32($i);
}, $array));
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$started_at = microtime(true);
foreach ($options as $key => $value) {
$memcache->add($key, $value, MEMCACHE_COMPRESSED, 36000);
}
$to_add = microtime(true) - $started_at;
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$started_at = microtime(true);
$results = $memcache->get(array_keys($options));
$to_get = microtime(true) - $started_at;
echo '<pre>';
echo sprintf("Took %f seconds to add\n", $to_add);
echo sprintf("Took %f seconds to get.\n", $to_get);
var_dump(array_values($results) === array_values($options));
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment