Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Usage: cd /var/www/sites/all/modules/civicrm/; cv scr front-bench.php
- for ($trial = 0; $trial < 3; $trial++) {
- echo "\n";
- $cacheSpecs = [
- [
- 'name' => "t{$trial}_decor",
- 'type' => array('*memory*'),
- 'withFront' => 'decor',
- ],
- [
- 'name' => "t{$trial}_fastdec",
- 'type' => array('*memory*'),
- 'withFront' => 'decor',
- ],
- [
- 'name' => "t{$trial}_tiered",
- 'type' => array('*memory*'),
- 'withFront' => 'tiered',
- ],
- [
- 'name' => "t{$trial}_direct",
- 'type' => array('*memory*'),
- 'withFront' => FALSE,
- ]
- ];
- $writeItems = 1000; // Total number of items to write
- $readTrials = 150; // Number of items each values is (re)read
- $readItems = 200; // Length of the subsequence of of items to read.
- foreach ($cacheSpecs as $cacheSpec) {
- CRM_Utils_Cache::create($cacheSpec)->clear();
- $writeStart = microtime(1);
- $cache = CRM_Utils_Cache::create($cacheSpec);
- for ($i = 0; $i < $writeItems; $i++) {
- $val = "value_$i ";
- for ($ch = 0; $ch < $i; $ch++) { $val .= '...'; }
- $cache->set("item_$i", "value_$i");
- }
- $writeStop = microtime(1);
- // Pick a random subsection and read it several times.
- $readOffset = rand(0, $writeItems - 1);;
- $readStart = microtime(1);
- $cache = CRM_Utils_Cache::create($cacheSpec);
- for ($readCount = 0; $readCount < $readTrials; $readCount++) {
- for ($i = 0; $i < $readItems; $i++) {
- $itemNum = ($i + $readOffset) % $writeItems;
- $val = $cache->get("item_$itemNum");
- }
- }
- $readStop = microtime(1);
- printf("%-15s write=%.4fs read=%.4fs\n",
- $cacheSpec['name'],
- $writeStop - $writeStart,
- $readStop - $readStart);
- }
- }
Add Comment
Please, Sign In to add comment