Как определить, какой метод работает быстрее? Имея трудное время, читая о Benchmark в документах Ruby и фактически реализуя его. БлагодарностиКак узнать, какой метод работает быстрее
def count_between(list_of_integers, lower_bound, upper_bound)
count = 0
list_of_integers.each do |x|
(x >= lower_bound && x <= upper_bound) ? count += 1 : next
end
count
end
или
def count_between(list_of_integers, lower_bound, upper_bound)
count = 0
list_of_integers.each do |x|
count += 1 if x.between?(lower_bound, upper_bound)
end
count
end
Модуль ['Benchmark'] (http://ruby-doc.org/stdlib-2.1.0/libdoc/benchmark/rdoc/Benchmark.html) не так уж прост в использовании. Что вы не понимаете в этом? – zwippie
Проверьте наличие [Gprof] (https://en.wikipedia.org/wiki/Gprof). – kenorb