class CompareSort
Public Class Methods
compare_all(info)
click to toggle source
# File lib/compare-sort.rb, line 26 def self.compare_all(info) data = info[:data] view = info[:view] sorting_methods = %w(HeapSort QuickSort SelectionSort BubbleSort ModifiedBubbleSort InsertionSort MergeSort) sorting_times = {} info_hash = { data: data.dup, timer: true } sorting_methods.each do |method| info_hash = { data: data.dup, sorting_method: method, timer: true } sorting_times[method] = self.run(info_hash) end if view View.compare_all(sorting_times.sort_by{|method, time| time}) end return sorting_times end
run(info)
click to toggle source
# File lib/compare-sort.rb, line 2 def self.run(info) data = info[:data] sorting_method = info[:sorting_method] timer = info[:timer] ValidateData.run(data) if timer sort = lambda { eval(sorting_method).run(data) } return self.timer(sort) else return eval(sorting_method).run(data) end end
timer(sorting_method)
click to toggle source
# File lib/compare-sort.rb, line 18 def self.timer(sorting_method) start_time = Time.now sorted_list = sorting_method.call end_time = Time.now return end_time - start_time end