Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. # class implementations up above elided...
  2.  
  3. if $0 == __FILE__
  4.  
  5.  
  6. # 0 1 2 3 4 5 6 7 8 9 10 11 12 13
  7. small_array = [27, 18, 28, 31, 41, 45, 26, 53, 58, 59, 90, 93, 97, 54]
  8.  
  9. medium_array = (0..200).map { rand(2**31) + 1 }
  10.  
  11. large_array = (0..10_000).map { rand(2**31) + 1 }
  12.  
  13. giant_array = (0..100_000).map { rand(2**31) + 1 }
  14.  
  15. # Sanity check...
  16. s = SmoothSort.new
  17. lm = s.sort(small_array.dup)
  18. lq = small_array.dup.sort
  19. raise Exception.new("Sanity Check! Sorted arrays don't match: #{lm.inspect}") unless lm == lq
  20.  
  21. # the benchmark_suite code isn't available, so use the standard Ruby benchmark
  22.  
  23. require "benchmark" # <== throws an error
  24.  
  25. Benchmark.ips do |x|
  26.  
  27. x.report("built-in sort small array") do |times|
  28. i = 0
  29. while i < times
  30. small_array.dup.sort
  31. i += 1
  32. end
  33. end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement