Skip to content

Instantly share code, notes, and snippets.

@cararemixed
Created April 6, 2021 03:03
Show Gist options
  • Save cararemixed/c232b888b9dbdaeb67967f357a3605df to your computer and use it in GitHub Desktop.
Save cararemixed/c232b888b9dbdaeb67967f357a3605df to your computer and use it in GitHub Desktop.
useless microbenchmark

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.

@yasoob
Copy link

yasoob commented Sep 12, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment