Last active
May 17, 2018 16:34
-
-
Save sspreitzer/1794f78b1b914d753d2784ae96473aaf to your computer and use it in GitHub Desktop.
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
# Sascha Spreitzer (c) 2018, MIT License | |
require 'net/http' | |
require 'thread' | |
url = ARGV[0] ||= 'http://example.com/' | |
many = ARGV[1] ||= 100 | |
res = {} | |
m = Mutex.new | |
thr = [] | |
start = Time.now | |
many.to_i.times do | |
thr << Thread.new do | |
h = Net::HTTP.get(URI(url)) | |
m.synchronize do | |
t = res.member?(h) | |
res[h] += 1 if t | |
res[h] = 1 unless t | |
end | |
end | |
end | |
thr.each { |th| th.join } | |
stop = Time.now | |
puts "#{res.size} different responses" | |
puts "" | |
res.each do |k, v| | |
puts "#{k[0..10]}..: #{v}" | |
end | |
puts "" | |
puts "Time elapsed: #{(stop-start).round(2)}s" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment