1 |
#!/usr/bin/perl |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
use Benchmark qw/:all/; |
6 |
use lib 'lib'; |
7 |
use Redis; |
8 |
use Redis::Hash; |
9 |
|
10 |
my $r = Redis->new; |
11 |
|
12 |
my %hash; |
13 |
tie %hash, 'Redis::Hash', 'hash'; |
14 |
|
15 |
my $i = 0; |
16 |
|
17 |
timethese( 100000, { |
18 |
'00_ping' => sub { $r->ping }, |
19 |
'10_set' => sub { $r->set( 'foo', $i++ ) }, |
20 |
'11_set_r' => sub { $r->set( 'bench-' . rand(), rand() ) }, |
21 |
'20_get' => sub { $r->get( 'foo' ) }, |
22 |
'21_get_r' => sub { $r->get( 'bench-' . rand() ) }, |
23 |
'30_incr' => sub { $r->incr( 'counter' ) }, |
24 |
'30_incr_r' => sub { $r->incr( 'bench-' . rand() ) }, |
25 |
'40_lpush' => sub { $r->lpush( 'mylist', 'bar' ) }, |
26 |
'40_lpush' => sub { $r->lpush( 'mylist', 'bar' ) }, |
27 |
'50_lpop' => sub { $r->lpop( 'mylist' ) }, |
28 |
'90_h_set' => sub { $hash{ 'test' . rand() } = rand() }, |
29 |
'90_h_get' => sub { my $a = $hash{ 'test' . rand() }; }, |
30 |
}); |