File: redis-benchmark.pl

package info (click to toggle)
libredis-fast-perl 0.34%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 492 kB
  • sloc: perl: 2,630; makefile: 7
file content (32 lines) | stat: -rwxr-xr-x 869 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl

use warnings;
use strict;
use Benchmark qw/:all/;
use lib 'lib';
use Redis::Fast;
use Redis::Fast::Hash;

my $r = Redis::Fast->new;

my %hash;
tie %hash, 'Redis::Fast::Hash', 'hash';

my $i = 0;

timethese(
  -5,
  { '00_ping'   => sub { $r->ping },
    '10_set'    => sub { $r->set('foo', $i++) },
    '11_set_r'  => sub { $r->set('bench-' . rand(), rand()) },
    '20_get'    => sub { $r->get('foo') },
    '21_get_r'  => sub { $r->get('bench-' . rand()) },
    '30_incr'   => sub { $r->incr('counter') },
    '30_incr_r' => sub { $r->incr('bench-' . rand()) },
    '40_lpush'  => sub { $r->lpush('mylist', 'bar') },
    '40_lpush'  => sub { $r->lpush('mylist', 'bar') },
    '50_lpop'   => sub { $r->lpop('mylist') },
    '90_h_set'  => sub { $hash{ 'test' . rand() } = rand() },
    '90_h_get'  => sub { my $a = $hash{ 'test' . rand() }; },
  }
);