Skip to content

Instantly share code, notes, and snippets.

@herewithme
Created December 3, 2015 23:47
Show Gist options
  • Save herewithme/e61a7399c1bd1b130e11 to your computer and use it in GitHub Desktop.
Save herewithme/e61a7399c1bd1b130e11 to your computer and use it in GitHub Desktop.
Benchmark for test memcached performance
<?php
// Initialize values: 1000000 keys of 20 bytes with 40 bytes of data
$c = 1000000;
$values = array();
for ($i=0;$i<$c;$i++) $values[sprintf('%020s',$i)]=sha1($i);
// Memcached
$m = new Memcached();
$m->addServer('10.0.101.82', 11211);
$start = microtime(true);
foreach ($values as $k => $v) $m->set($k, $v, 3600);
$time = microtime(true)-$start;
echo "memcached set: $time\n";
$start = microtime(true);
foreach ($values as $k => $v) $m->get($k);
$time = microtime(true)-$start;
echo "memcached get: $time\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment