Created
August 24, 2017 15:46
-
-
Save exAspArk/abd3aca53b1497156cc7761cfa1e452e to your computer and use it in GitHub Desktop.
Compare Process vs Thread creation / deletion time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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