Created
October 15, 2018 14:13
-
-
Save jakub-roman/b70c94a93a3ec70dff40c510f951b469 to your computer and use it in GitHub Desktop.
perl-redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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