Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some basic memory usage benchmarks. #271

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions benchmark/memory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env ruby

# require "benchmark/memory"

# Benchmark.memory do |benchmark|
# benchmark.report("Thread.new{}") do
# Thread.new{true}.join
# end

# benchmark.report("Fiber.new{}") do
# Fiber.new{true}.resume
# end

# benchmark.compare!
# end

require 'memory'

report = Memory.report do
Thread.new{true}.join
Fiber.new{true}.resume
end

report.print
18 changes: 18 additions & 0 deletions benchmark/memory/fibers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

pid = fork do
fibers = 100.times.map do
Fiber.new{loop{Fiber.yield}}.resume

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed something, but doesn't this only run once, while the thread example sleeps forever?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the fibers and threads are still alive at the point where you measure memory usage. Does that seem sufficient?

end

sleep
end

sleep 1

require 'process/metrics'
metrics = Process::Metrics::General.capture(pid: pid)

pp metrics

Process.kill(:TERM, pid)
18 changes: 18 additions & 0 deletions benchmark/memory/threads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

pid = fork do
threads = 100.times.map do
Thread.new{sleep}
end

threads.each(&:join)
end

sleep 1

require 'process/metrics'
metrics = Process::Metrics::General.capture(pid: pid)

pp metrics

Process.kill(:TERM, pid)
7 changes: 7 additions & 0 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@
gem "bake-github-pages"
gem "utopia-project"
end

group :benchmark do
gem "benchmark-ips"
gem "benchmark-memory"
gem "memory"
gem "process-metrics"
end