Skip to content

Instantly share code, notes, and snippets.

@exAspArk
Created August 24, 2017 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exAspArk/abd3aca53b1497156cc7761cfa1e452e to your computer and use it in GitHub Desktop.
Save exAspArk/abd3aca53b1497156cc7761cfa1e452e to your computer and use it in GitHub Desktop.
Compare Process vs Thread creation / deletion time
# gem install benchmark-ips
require 'benchmark/ips'
Benchmark.ips do |x|
x.warmup = 0
x.report("threads") do
thread = Thread.new { puts 'thread' }
thread.join
end
x.report("processes") do |times|
fork { puts 'process' }
Process.wait
end
x.compare!
end
# Warming up --------------------------------------
# threads 1.000 i/100ms
# processes 1.000 i/100ms
# Calculating -------------------------------------
# 32.951k (±22.7%) i/s - 125.769k in 4.857991s
# 244.113 (± 9.8%) i/s - 1.207k in 4.997751s
# Comparison:
# threads: 32950.7 i/s
# processes: 244.1 i/s - 134.98x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment