#! /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 time = Time.now size = memoryusage if ARGV.length > 1 db = ADB::new db.open(ARGV[1] + "#bnum=" + rnum.to_s + "#mode=wct#xmsiz=0") || raise("open failed") (0...rnum).each do |i| buf = sprintf("%08d", i) db.put(buf, buf) end time = Time.now - time GC.start size = memoryusage - size db.close else hash = Hash.new (0...rnum).each do |i| buf = sprintf("%08d", i) hash[buf] = buf end time = Time.now - time GC.start size = memoryusage - size end printf("Time: %.3f sec.\n", time) printf("Usage: %.3f MB\n", size)