Created
October 3, 2023 20:15
-
-
Save rollerozxa/62540b7a263c39520d0dccc17cf53ce5 to your computer and use it in GitHub Desktop.
APCu vs memcached benchmark script
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 | |
// This script depends on some classes found in principia-web: | |
// https://github.com/principia-game/principia-web | |
$prof = new Profiler(); | |
$cacheSystems = [ | |
'apcu' => new CacheAPCu(), | |
'memcached_tcp' => new CacheMemcached([ ['127.0.0.1', 11211] ]), | |
'memcached_udp' => new CacheMemcached([ ['127.0.0.1', 11212] ]), | |
'memcached_unix' => new CacheMemcached([ ['/run/memcached/memcached.sock', 0] ]) | |
]; | |
foreach ($cacheSystems as $system => $c) { | |
$prof->resetTime(); | |
$c->set('amanda', 'test'); | |
for ($i = 0; $i < 50000; $i++) { | |
$c->get('amanda'); | |
} | |
printf("Read 50000 existant test for %s: %1.3fs\n", $system, $prof->getTime()); | |
} | |
foreach ($cacheSystems as $system => $c) { | |
$prof->resetTime(); | |
for ($i = 0; $i < 50000; $i++) { | |
$c->set('test_'.$i, 'amanda'); | |
} | |
printf("Write 50000 test for %s: %1.3fs\n", $system, $prof->getTime()); | |
} | |
$randomCrap = random_bytes(8*1024); | |
foreach ($cacheSystems as $system => $c) { | |
$prof->resetTime(); | |
for ($i = 0; $i < 50000; $i++) { | |
$c->set('test2_'.$i, $randomCrap); | |
} | |
printf("Write 50000 (8k) test for %s: %1.3fs\n", $system, $prof->getTime()); | |
} | |
die(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment