forked from grinya007/2q
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.pl
More file actions
executable file
·39 lines (32 loc) · 810 Bytes
/
test.pl
File metadata and controls
executable file
·39 lines (32 loc) · 810 Bytes
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
33
34
35
36
37
38
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin qw/$RealBin/;
use lib $RealBin.'/lib';
use Cache::TwoQ;
use Time::HiRes qw/time/;
my $statm = statm();
my $time = time();
my $cache = Cache::TwoQ->new(2000);
my $hits = 0;
my $count = 0;
while (<STDIN>) {
$count++;
if ($cache->get($_)) {
$hits++;
}
else {
$cache->set($_, ($_ x 100));
}
}
$statm = statm() - $statm;
$time = time() - $time;
printf "worked out %d keys\n", $count;
printf "\thit rate:\t%0.3f %%\n", (100*$hits/$count);
printf "\tmemory:\t\t%0.3f Mb\n", ($statm/1024/1024);
printf "\ttime:\t\t%0.3f s\n", ($time);
sub statm {
my $pages = (join('', `cat /proc/$$/statm`) =~ /^\d+\s+(\d+)/)[0];
my $page_size = (join('', `getconf PAGESIZE`) =~ /^(\d+)/)[0];
return $pages*$page_size;
}