Created
June 28, 2011 08:54
-
-
Save jennifersmith/1050765 to your computer and use it in GitHub Desktop.
Comparison of long string generation
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' | |
lengths = [10, 100 , 1000, 10000, 100000, 1000000] | |
Benchmark.bm do |x| | |
lengths.each do |length| | |
x.report("Length = #{length}\t\t\t") {(0...length.to_i).map{ ('a'..'z').to_a[rand(26)] }} | |
x.report("Same without rand = #{length}\t\t\t") {(0...length.to_i).map{ ('a'..'z').to_a[1] }} | |
x.report("Fixed characters Length = #{length}\t\t\t") {"x" * length} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for 1000000 characters random takes 24 seconds on my machine!