Skip to content

Instantly share code, notes, and snippets.

@auxesis
Created June 22, 2012 07:18
Show Gist options
  • Save auxesis/2970957 to your computer and use it in GitHub Desktop.
Save auxesis/2970957 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'benchmark'
require 'socket'
i = 10_000
Benchmark.bm(9) do |x|
x.report("shell out") do
i.times { `hostname -f`.strip }
end
x.report("socket") do
i.times { Socket.gethostbyname(Socket.gethostname).first }
end
end
~ ➔ ruby fqdn-benchmark.rb
user system total real
shell out 1.280000 11.500000 38.610000 ( 49.029772)
socket 1.330000 2.220000 3.550000 ( 22.050667)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment