diff --git a/benchmark/memory.rb b/benchmark/memory.rb new file mode 100755 index 00000000..8305a357 --- /dev/null +++ b/benchmark/memory.rb @@ -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 \ No newline at end of file diff --git a/benchmark/memory/fibers.rb b/benchmark/memory/fibers.rb new file mode 100755 index 00000000..f409bcf7 --- /dev/null +++ b/benchmark/memory/fibers.rb @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +pid = fork do + fibers = 100.times.map do + Fiber.new{loop{Fiber.yield}}.resume + end + + sleep +end + +sleep 1 + +require 'process/metrics' +metrics = Process::Metrics::General.capture(pid: pid) + +pp metrics + +Process.kill(:TERM, pid) diff --git a/benchmark/memory/threads.rb b/benchmark/memory/threads.rb new file mode 100755 index 00000000..5af01ecd --- /dev/null +++ b/benchmark/memory/threads.rb @@ -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) diff --git a/gems.rb b/gems.rb index 22c25660..a86fa992 100644 --- a/gems.rb +++ b/gems.rb @@ -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