Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $client = new \Predis\Client(
- [
- 'host' => 'localhost',
- 'port' => 6380,
- 'password' => 'pass',
- 'database' => 1,
- ],
- [
- 'prefix' => 'benchmark'
- ]
- );
- $hashKey = 'hashKey';
- $iterationsCount = 100;
- $maxFieldCount = 20000;
- echo implode(' ', [
- str_pad('Count', 6, ' ', STR_PAD_LEFT),
- str_pad('Set (ms)', 20, ' ', STR_PAD_LEFT),
- str_pad('Del (ms)', 20, ' ', STR_PAD_LEFT),
- ]) . PHP_EOL;
- $client->del([$hashKey]);
- for ($hashFieldCount = 0; $hashFieldCount < $maxFieldCount; $hashFieldCount += 1000) {
- $durationSetMs = 0;
- $durationDelMs = 0;
- for ($i = 0; $i < $iterationsCount; $i++) {
- $keys = [];
- for ($j = 0; $j <= $hashFieldCount; $j++) {
- $key = 'hashField' . $j;
- $keys[] = $key;
- }
- // multi set fields to redis hash
- $start = microtime(true);
- $client->hmset($hashKey, array_fill_keys($keys, 42));
- $durationSetMs += (microtime(true) - $start) * 1000 / $iterationsCount;
- // multi delete fields on redis hash
- $start = microtime(true);
- $client->hdel('hashKey', $keys);
- $durationDelMs += (microtime(true) - $start) * 1000 / $iterationsCount;
- }
- echo implode(' ', [
- str_pad(count($keys), 6, ' ', STR_PAD_LEFT),
- str_pad($durationSetMs, 20, ' ', STR_PAD_LEFT),
- str_pad($durationDelMs, 20, ' ', STR_PAD_LEFT),
- ]) . PHP_EOL;
- }
- $client->del([$hashKey]);
Add Comment
Please, Sign In to add comment