Guest User

Untitled

a guest
Dec 14th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <?php
  2.  
  3. $client = new \Predis\Client(
  4. [
  5. 'host' => 'localhost',
  6. 'port' => 6380,
  7. 'password' => 'pass',
  8. 'database' => 1,
  9. ],
  10. [
  11. 'prefix' => 'benchmark'
  12. ]
  13. );
  14.  
  15. $hashKey = 'hashKey';
  16.  
  17. $iterationsCount = 100;
  18. $maxFieldCount = 20000;
  19.  
  20. echo implode(' ', [
  21. str_pad('Count', 6, ' ', STR_PAD_LEFT),
  22. str_pad('Set (ms)', 20, ' ', STR_PAD_LEFT),
  23. str_pad('Del (ms)', 20, ' ', STR_PAD_LEFT),
  24. ]) . PHP_EOL;
  25.  
  26. $client->del([$hashKey]);
  27. for ($hashFieldCount = 0; $hashFieldCount < $maxFieldCount; $hashFieldCount += 1000) {
  28. $durationSetMs = 0;
  29. $durationDelMs = 0;
  30. for ($i = 0; $i < $iterationsCount; $i++) {
  31. $keys = [];
  32. for ($j = 0; $j <= $hashFieldCount; $j++) {
  33. $key = 'hashField' . $j;
  34. $keys[] = $key;
  35. }
  36.  
  37. // multi set fields to redis hash
  38. $start = microtime(true);
  39. $client->hmset($hashKey, array_fill_keys($keys, 42));
  40. $durationSetMs += (microtime(true) - $start) * 1000 / $iterationsCount;
  41.  
  42. // multi delete fields on redis hash
  43. $start = microtime(true);
  44. $client->hdel('hashKey', $keys);
  45. $durationDelMs += (microtime(true) - $start) * 1000 / $iterationsCount;
  46. }
  47.  
  48. echo implode(' ', [
  49. str_pad(count($keys), 6, ' ', STR_PAD_LEFT),
  50. str_pad($durationSetMs, 20, ' ', STR_PAD_LEFT),
  51. str_pad($durationDelMs, 20, ' ', STR_PAD_LEFT),
  52. ]) . PHP_EOL;
  53. }
  54.  
  55. $client->del([$hashKey]);
Add Comment
Please, Sign In to add comment