Znajdź najmniejszą i największą liczbę! Ruby 3.2 YJIT WebAssembly. Warto też dopisać wersję języka i kompilatora/interpretera w którym dany program został skompilowany i uruchomiony.
# create a method that finds the minimum value passed into it
def find_min(*args) # allows me to pass in any amount of arguments
min_num = args[0]
args.each do |number|
if number < min_num
min_num = number
end
end
min_num
end
puts(find_min(1, 5, -3, 6, 8, 0, -10, 121, 3, 4, 4, 5))
# create a method that finds the maximum value passed into it
def find_max(*args) # allows me to pass in any amount of arguments
max_num = args[0]
args.each do |number|
if number > max_num
max_num = number
end
end
max_num
end
puts(find_max(1, 5, -3, 6, 8, 0, -10, 121, 3, 4, 4, 5))
reduce
, bo okazały się parokrotnie wolniejsze od odpowiadających imfor
:(i
, to użyłem .iter() oraz .zip() to dopiero przyśpieszyło. Ale jeszcze będę weryfikował, czy naprawdę tak jest. Więc ten WebAssembly miał tyle dawać pod kątem wydajności,a póki co tyle daje, że trzeba dodatkowe benchmarki robić