Skip to content

Instantly share code, notes, and snippets.

@ekho
Last active December 16, 2015 15:19
Show Gist options
  • Save ekho/5454679 to your computer and use it in GitHub Desktop.
Save ekho/5454679 to your computer and use it in GitHub Desktop.
compare leveldb-daemon (https://github.com/mambaru/leveldb-daemon), memcached & redis through phpredis (https://github.com/nicolasff/phpredis) leveldb-daemon: ~34,6s memcached: ~6.5s redis: ~5.1s
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__));
include_once 'JsonRpc.php';
$config = include 'config.php';
$connect = new JsonRpc_Connection($config['host'], $config['port']);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$connect->request('set', array(
'foo' => uniqid('foo'),
'bar' => uniqid('bar'),
));
$connect->process();
$future = $connect->request('get', array('foo', 'bar'));
$connect->process();
$future = $connect->request('get', array('foo', 'bar'));
$connect->process();
$future = $connect->request('get', array('foo', 'bar'));
$connect->process();
$future = $connect->request('get', array('foo', 'bar'));
$connect->process();
}
$t2 = microtime(true);
echo 'leveldb = ', ($t2-$t1), PHP_EOL;
//-------------------------------------------------
$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$memcache->set('foo', uniqid('foo'));
$memcache->set('bar', uniqid('bar'));
$memcache->get(array('foo', 'bar'));
$memcache->get(array('foo', 'bar'));
$memcache->get(array('foo', 'bar'));
$memcache->get(array('foo', 'bar'));
}
$t2 = microtime(true);
echo 'memcache = ', ($t2-$t1), PHP_EOL;
//-------------------------------------------------
$redis = new Redis();
$redis->connect('localhost', 6379);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
$redis->mset(array(
'foo' => uniqid('foo'),
'bar' => uniqid('bar'),
));
$redis->mGet(array('foo', 'bar'));
$redis->mGet(array('foo', 'bar'));
$redis->mGet(array('foo', 'bar'));
$redis->mGet(array('foo', 'bar'));
}
$t2 = microtime(true);
echo 'redis = ', ($t2-$t1), PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment