Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
perl-redis
#!/usr/bin/env perl
use strict;
use warnings;
use Redis;
use Data::Dumper;
use Time::HiRes qw/time/;
my $r = Redis->new();
my $num = 10000;
# set
my $sets = 0;
for( my $i = 0; $i < $num; $i++ )
{
my $rand = rs(10);
my $item_start = time;
$r->set($i => $rand);
my $item_end = time;
my $diff = $item_end - $item_start;
$sets += $diff;
}
# get
my $gets = 0;
for( my $i = 0; $i < $num; $i++ )
{
my $item_start = time;
my $item = $r->get($i);
my $item_end = time;
my $diff = $item_end - $item_start;
$gets += $diff;
}
my $set = $sets / $num * 1000000;
my $get = $gets / $num * 1000000;
print "Avg set: $set\n";
print "Avg get: $get\n";
sub rs
{
my $length_of_randomstring=shift;# the length of
my @chars=('a'..'z','A'..'Z','0'..'9','_');
my $random_string;
foreach (1..$length_of_randomstring)
{
# rand @chars will generate a random
# number between 0 and scalar @chars
$random_string.=$chars[rand @chars];
}
return $random_string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.