Sha256: a768fbb47ee9df1c7db266aaabc0bee02e4be34160d254a76e97b61b2f5abc6f
Contents?: true
Size: 564 Bytes
Versions: 1
Compression:
Stored size: 564 Bytes
Contents
# frozen_string_literal: true 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.4.0 | benchmark/int_to_str.rb |