Created
March 30, 2017 20:10
-
-
Save chuckremes/6e63fb8ea0635b02b687001a1b42d83a to your computer and use it in GitHub Desktop.
This file contains 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
# class implementations up above elided... | |
if $0 == __FILE__ | |
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | |
small_array = [27, 18, 28, 31, 41, 45, 26, 53, 58, 59, 90, 93, 97, 54] | |
medium_array = (0..200).map { rand(2**31) + 1 } | |
large_array = (0..10_000).map { rand(2**31) + 1 } | |
giant_array = (0..100_000).map { rand(2**31) + 1 } | |
# Sanity check... | |
s = SmoothSort.new | |
lm = s.sort(small_array.dup) | |
lq = small_array.dup.sort | |
raise Exception.new("Sanity Check! Sorted arrays don't match: #{lm.inspect}") unless lm == lq | |
# the benchmark_suite code isn't available, so use the standard Ruby benchmark | |
require "benchmark" # <== throws an error | |
Benchmark.ips do |x| | |
x.report("built-in sort small array") do |times| | |
i = 0 | |
while i < times | |
small_array.dup.sort | |
i += 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment