For ruby:
require 'benchmark'
puts Benchmark.measure {(1..100_000).reduce(&:*); nil}.realI 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.
for ruby I get 3.9 sec
for elixir I get 4.891474 sec
in my apple m1 air (16g)