Created
July 9, 2015 06:05
-
-
Save hirose31/47496cdd022c5e88632e 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
#!/usr/bin/env ruby | |
require 'socket' | |
$stdout.sync = true | |
$stderr.sync = true | |
@lock = Mutex.new | |
def main | |
th = [] | |
n = 300 | |
err = 0 | |
for i in 1..n | |
th << Thread.new(i) do |i| | |
begin | |
ip = Socket.getaddrinfo('www.irori.org', nil) | |
rescue SocketError => e | |
@lock.synchronize do | |
err += 1 | |
end | |
puts format("[%6d] %s\n", i, e) | |
else | |
puts format("[%6d] %s\n", i, ip[0][3]) | |
end | |
end | |
end | |
th.each {|t| t.join} | |
puts RUBY_VERSION | |
puts format("failed %d/%d %.2f%%", err, n, err.to_f/n.to_f*100) | |
exit 0 | |
end | |
main if __FILE__ == $PROGRAM_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment