Skip to content

Instantly share code, notes, and snippets.

@acook
Created April 8, 2014 16:13
Show Gist options
  • Select an option

  • Save acook/10149670 to your computer and use it in GitHub Desktop.

Select an option

Save acook/10149670 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# "We should forget about small efficiencies, say about 97% of the time:
# premature optimization is the root of all evil"
# - Donald Knuth
require 'securerandom'
def rarray size
size.times.inject(Array.new) do |result, _|
result << SecureRandom.hex
end
end
rps = 100
size = 1000
a = rarray size
t1 = Time.new
rps.times do
a.sort
end
t2 = Time.new
r1 = t2 - t1
t1 = Time.new
rps.times do
a.sort!
end
t2 = Time.new
r2 = t2 - t1
puts "time1: #{r1.inspect}"
puts "time2: #{r2.inspect}"
puts "diff : #{r1 - r2}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment