-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmemory.rb
More file actions
39 lines (29 loc) · 708 Bytes
/
memory.rb
File metadata and controls
39 lines (29 loc) · 708 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
# frozen_string_literal: true
require_relative "../lib/goru"
def current_memory_usage
`ps -o rss #{Process.pid}`.lines.last.to_i
end
$size = 10_000
class Profiler
include Goru
def initialize(size:)
@size = size
end
def call
@size.times do
go(true) { |routine|
if routine.state
routine.update(false)
routine.sleep(rand)
else
routine.finished
end
}
end
end
end
profiler = Profiler.new(size: $size)
starting_memory_usage = current_memory_usage
profiler.call
total_memory_usage_in_bytes = (current_memory_usage - starting_memory_usage).to_f * 1024
puts "#{total_memory_usage_in_bytes / $size} bytes per routine"