File: memsize.pl

package info (click to toggle)
libtokyocabinet-perl 1.34-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch
  • size: 560 kB
  • ctags: 394
  • sloc: perl: 5,439; sh: 47; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 826 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
33
34
35
36
37
38
39
#! /usr/bin/perl

use lib qw(./blib/lib ./blib/arch);
use strict;
use warnings;
use TokyoCabinet;
use Time::HiRes qw(gettimeofday);

sub memoryusage {
    my $status = `cat /proc/$$/status`;
    my @lines = split("\n", $status);
    foreach my $line (@lines){
        if($line =~ /^VmRSS:/){
            $line =~ s/.*:\s*(\d+).*/$1/;
            return int($line) / 1024.0;
        }
    }
    return -1;
}

my $rnum = 1000000;
if(scalar(@ARGV) > 0){
    $rnum = int($ARGV[0]);
}

my %hash;
if(scalar(@ARGV) > 1){
    tie(%hash, "TokyoCabinet::ADB", $ARGV[1]) || die("tie failed");
}

my $stime = gettimeofday();
for(my $i = 0; $i < $rnum; $i++){
    my $buf = sprintf("%08d", $i);
    $hash{$buf} = $buf;
}
my $etime = gettimeofday();

printf("Time: %.3f sec.\n", $etime - $stime);
printf("Usage: %.3f MB\n", memoryusage());