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.
@coolmenu I'm curious what build versions you're using and if you're using rosetta 2. I don't have an M1 Mac to try this with but I'd expect the erlang JIT to work quite well with it as it generates code during startup so translation caches can be effective. You might see it drop well below ruby's runtime. If you're using homebrew + rosetta you can install the JIT version with
brew install --HEAD erlang
.For hardware info, I'm running this on an 8-core i9 with macOS 11.2.3.