Created
December 15, 2012 05:46
-
-
Save sssionggg/4291574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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