memtest.rb
846 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
39
40
41
require 'lib/arrayfields'
STDOUT.sync = true
n = Integer((ARGV.shift or (2 ** 16)))
#
# hash mem usage - around 13016 on my machine
#
fork do
a = []
n.times do
a << {'a' => 0, 'b' => 1, 'c' => 2}
end
puts "pid <#{ Process.pid }>"
system "ps wwwaux | grep #{ Process.pid }"
print "run top to examine mem usage of <#{ n }> hashes (enter when done) >"
STDIN.gets
end
Process.wait
#
# arrayfields mem usage - around 8752 on my machine
#
fork do
fields = %w( a b c )
a = []
n.times do
t = [0,1,2]
t.fields = fields
t.extend ArrayFields
a << [0,1,2]
end
puts "pid <#{ Process.pid }>"
system "ps wwwaux | grep #{ Process.pid }"
print "run top to examine mem usage of <#{ n }> extended arrays (enter when done) >"
STDIN.gets
end
Process.wait