Guest User

Untitled

a guest
Jan 21st, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2. // Usage: cd /var/www/sites/all/modules/civicrm/; cv scr front-bench.php
  3.  
  4. for ($trial = 0; $trial < 3; $trial++) {
  5. echo "\n";
  6. $cacheSpecs = [
  7. [
  8. 'name' => "t{$trial}_decor",
  9. 'type' => array('*memory*'),
  10. 'withFront' => 'decor',
  11. ],
  12. [
  13. 'name' => "t{$trial}_fastdec",
  14. 'type' => array('*memory*'),
  15. 'withFront' => 'decor',
  16. ],
  17. [
  18. 'name' => "t{$trial}_tiered",
  19. 'type' => array('*memory*'),
  20. 'withFront' => 'tiered',
  21. ],
  22. [
  23. 'name' => "t{$trial}_direct",
  24. 'type' => array('*memory*'),
  25. 'withFront' => FALSE,
  26. ]
  27. ];
  28.  
  29. $writeItems = 1000; // Total number of items to write
  30. $readTrials = 150; // Number of items each values is (re)read
  31. $readItems = 200; // Length of the subsequence of of items to read.
  32.  
  33. foreach ($cacheSpecs as $cacheSpec) {
  34. CRM_Utils_Cache::create($cacheSpec)->clear();
  35.  
  36. $writeStart = microtime(1);
  37. $cache = CRM_Utils_Cache::create($cacheSpec);
  38. for ($i = 0; $i < $writeItems; $i++) {
  39. $val = "value_$i ";
  40. for ($ch = 0; $ch < $i; $ch++) { $val .= '...'; }
  41. $cache->set("item_$i", "value_$i");
  42. }
  43. $writeStop = microtime(1);
  44.  
  45. // Pick a random subsection and read it several times.
  46. $readOffset = rand(0, $writeItems - 1);;
  47. $readStart = microtime(1);
  48. $cache = CRM_Utils_Cache::create($cacheSpec);
  49. for ($readCount = 0; $readCount < $readTrials; $readCount++) {
  50. for ($i = 0; $i < $readItems; $i++) {
  51. $itemNum = ($i + $readOffset) % $writeItems;
  52. $val = $cache->get("item_$itemNum");
  53. }
  54. }
  55. $readStop = microtime(1);
  56.  
  57. printf("%-15s write=%.4fs read=%.4fs\n",
  58. $cacheSpec['name'],
  59. $writeStop - $writeStart,
  60. $readStop - $readStart);
  61. }
  62.  
  63. }
Add Comment
Please, Sign In to add comment