Sha256: e7cd272c3416a6ebf599c28c02808b227009cb67c13f2d5ca861b3539bc71808
Contents?: true
Size: 524 Bytes
Versions: 2
Compression:
Stored size: 524 Bytes
Contents
require 'benchmark' require 'ipaddr' require 'ipconverter' def ruby_shift(ip) [ (ip >> 24) & 255, (ip >> 16) & 255, (ip >> 8) & 255, (ip >> 0) & 255 ].join('.') end ips = 0..999999 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('C shifts') { ips.each { |ip| IpConverter.int_to_str(ip) } } x.report('noop') { ips.each { |ip| ip } } end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ipconverter-0.3.0 | benchmark/int_to_str.rb |
ipconverter-0.2.0 | benchmark/int_to_str.rb |