Created
April 8, 2014 16:13
-
-
Save acook/10149670 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
| #!/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