For ruby:
require 'benchmark'
puts Benchmark.measure {(1..100_000).reduce(&:*); nil}.real
I get 7.48
to 7.68
seconds as the runtime on ruby 2.6.3 and 7.71
to 8.08
for ruby 3.0.0.
For elixir:
defmodule Factorial do
def run do
Enum.reduce(1..100_000, 1, & &1 * &2)
:ok
end
end
micros = :timer.tc(Factorial, :run, []) |> elem(0)
IO.puts "#{micros / 1_000_000} seconds"
I get 4.68
to 4.71
seconds for Erlang/OTP 24 RC2 with Elixir 1.11.4.
Ran both in the interactive shells. Here is what I got:
1.052038 seconds for Elixir (Erlang/OTP 26 [erts-14.0.2])
4.762765 seconds for Ruby (irb 1.6.2)
Machine is intel-based Macbook Pro 32GB 8 core i9.