public
Description: The tokyo cabinet ruby interface wrapped up in a gem
Homepage:
Clone URL: git://github.com/careo/tokyocabinet-ruby.git
Norman Clarke (author)
Wed May 20 09:05:47 -0700 2009
careo (committer)
Wed May 20 11:17:43 -0700 2009
tokyocabinet-ruby / memsize.rb
100755 39 lines (32 sloc) 0.66 kb
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/ruby
 
require 'tokyocabinet'
include TokyoCabinet
 
def memoryusage()
  status = `cat /proc/#{$$}/status`
  lines = status.split("\n")
  lines.each do |line|
    if line =~ /^VmRSS:/
      line.gsub!(/.*:\s*(\d+).*/, '\1')
      return line.to_i / 1024.0
    end
  end
  return -1;
end
 
rnum = 1000000;
if ARGV.length > 0
  rnum = ARGV[0].to_i
end
 
if ARGV.length > 1
  hash = ADB::new
  hash.open(ARGV[1]) || raise("open failed")
else
  hash = Hash.new
end
 
stime = Time.now
(0...rnum).each do |i|
  buf = sprintf("%08d", i)
  hash[buf] = buf
end
etime = Time.now
 
printf("Time: %.3f sec.\n", etime - stime)
printf("Usage: %.3f MB\n", memoryusage)