Skip to content

Instantly share code, notes, and snippets.

@foxweb
Last active March 16, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxweb/3dfacf3ba0ca2a871abc4147b2020245 to your computer and use it in GitHub Desktop.
Save foxweb/3dfacf3ba0ca2a871abc4147b2020245 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 100_000
abc = ('A'..'Z').to_a
Benchmark.bm do |x|
x.report { n.times { rand(65..90).chr } }
x.report { n.times { rand('A'.ord..'Z'.ord).chr } }
x.report { n.times { ('A'..'Z').to_a.sample } }
x.report { n.times { abc.sample } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment