public
Created

base62 convertor in ruby

  • Download Gist
benchmark_alphadecimal.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'rubygems'
require 'benchmark'
require 'alphadecimal'
 
time = Benchmark.measure do
1_000_000.times do |i|
encode = i.alphadecimal
decode = encode.alphadecimal
raise "Assertion error!" unless i == decode
end
end
 
puts time # 17.060000 0.050000 17.110000 ( 17.507562)
benchmark_base62.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'rubygems'
require 'benchmark'
require 'base62'
 
time = Benchmark.measure do
1_000_000.times do |i|
encode = i.base62_encode
decode = encode.base62_decode
raise "Assertion error!" unless i == decode
end
end
 
puts time # 9.600000 0.020000 9.620000 ( 9.802189)
benchmark_radix62.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'rubygems'
require 'benchmark'
require 'radix62'
 
time = Benchmark.measure do
1_000_000.times do |i|
encode = i.encode62
decode = encode.decode62
raise "Assertion error!" unless i == decode
end
end
 
puts time # 19.070000 0.040000 19.110000 ( 19.483596)
benchmark_yab62.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
require 'rubygems'
require 'benchmark'
require 'yab62'
 
time = Benchmark.measure do
1_000_000.times do |i|
encode = i.encode62
decode = encode.decode62
raise "Assertion error!" unless i == decode
end
end
 
puts time # 0.550000 0.000000 0.550000 ( 0.605562)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.