Last active
August 23, 2022 11:53
-
-
Save shikendon/b9c0e0041c8cec11e3f6bbe9fa987c0b to your computer and use it in GitHub Desktop.
Used in RubyConf Taiwan 2016 https://www.slideshare.net/shikendon/crawler-from-zero
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
#!/usr/bin/env ruby | |
require "benchmark" | |
require "httparty" | |
require "parallel" | |
# You need to modify your open file limit | |
# if you trying to run this on Mac OS | |
Benchmark.bmbm do |x| | |
x.report("Ruby Thread.new") do | |
threads = [] | |
1000.times do | |
threads << Thread.new do | |
_response = HTTParty.get("https://www.facebook.com/") | |
end | |
end | |
threads.map(&:join) | |
end | |
x.report("Ruby Parallel") do | |
Parallel.each(1..1000, in_threads: 1000) do | |
_response = HTTParty.get("https://www.facebook.com/") | |
end | |
end | |
x.report("Python threading") do | |
`python3 threading_test.py` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment