Skip to content

Instantly share code, notes, and snippets.

@siong1987
Created December 15, 2012 05:46
Show Gist options
  • Save siong1987/4291574 to your computer and use it in GitHub Desktop.
Save siong1987/4291574 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'yab62'
def generate_token(length)
(1..length).collect { (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }.join
end
def generate_mod_token(length)
(rand(62**length)).encode62.rjust(length,rand(62).encode62)
end
Benchmark.bm do |b|
b.report("#{10000.to_s.rjust(5, " ")} mod_records"){ 10000.times{ generate_mod_token(5) } }
b.report("#{10000.to_s.rjust(5, " ")} records "){ 10000.times{ generate_token(5) } }
end
user system total real
10000 mod_records 0.010000 0.000000 0.010000 ( 0.015380)
10000 records 0.050000 0.000000 0.050000 ( 0.055107)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment