Created
August 3, 2011 09:47
-
-
Save k-holy/1122279 to your computer and use it in GitHub Desktop.
php-memcacheのてすと
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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