Sha256: 481021257357fa1cf586ff6054292a1bb4b47fbb793fe58fe01f73c1ff9fcd69

Contents?: true

Size: 533 Bytes

Versions: 1

Compression:

Stored size: 533 Bytes

Contents

require 'benchmark'
require 'ipaddr'
require 'ipconverter'

def self.ruby_shift(ip)
  [
    (ip >> 24) & 255,
    (ip >> 16) & 255,
    (ip >> 8) & 255,
    (ip >> 0) & 255
  ].join('.')
end

ips = 0..999_999

puts 'iterations: 1,000,000'

Benchmark.bmbm do |x|
  x.report('IPAddr#to_s') { ips.each { |ip| IPAddr.new(ip, Socket::AF_INET).to_s } }
  x.report('Ruby shifts') { ips.each { |ip| ruby_shift(ip) } }
  x.report('IpConverter') { ips.each { |ip| IpConverter.int_to_str(ip) } }
  x.report('noop') { ips.each { |ip| ip } }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ipconverter-0.3.1 benchmark/int_to_str.rb