Skip to content

Instantly share code, notes, and snippets.

@Lakret
Last active March 28, 2019 02:28
Show Gist options
  • Save Lakret/45b73833021ec8f8f4e225aabc983ed5 to your computer and use it in GitHub Desktop.
Save Lakret/45b73833021ec8f8f4e225aabc983ed5 to your computer and use it in GitHub Desktop.

Scala 10 million (with 1 million in memory):

def time[R](block: => R): R = {
    val t0 = System.nanoTime()
    val result = block
    val t1 = System.nanoTime()
    println("Elapsed time: " + (t1 - t0) / 1e9 + " s.")
    result
}

scala> time { Map((for (x <- 1l to 10000000L) yield ((x.toString(), x))) : _*) }
Elapsed time: 7.318117769 s.

Elixir 10 million (w/o 1 million in memory):

iex(8)> {t, r} = :timer.tc(fn -> 1..10_000_000 |> Map.new(fn x -> {to_string(x), x} end) end) |> (fn {t, r} -> {t / 1000000, r} end).()
{39.230322,
 %{
   "7983953" => 7983953,
   "6354099" => 6354099,
   "6488809" => 6488809,

Elixir 10 million (with 1 million in memory):

iex(2)>  {t, r} = :timer.tc(fn -> 1..10_000_000 |> Map.new(fn x -> {to_string(x), x} end) end) |> (fn {t, r} -> {t / 1000000, r} end).()
{43.353361,
 %{
   "7983953" => 7983953,
   "6354099" => 6354099,
   "6488809" => 6488809,
...

Julia 10 million (with 1 million in memory):

julia> @time Dict(string(i) => i for i=1:10000000)
  6.976514 seconds (20.08 M allocations: 1.426 GiB, 40.77% gc time)
Dict{String,Int64} with 10000000 entries:
  "3583806" => 3583806
  "6912368" => 6912368
  "7638696" => 7638696
...

Julia sum 10 mil. array

julia> @time sum(Array(1:10000000))
  0.034530 seconds (8 allocations: 76.294 MiB)
50000005000000

Elixir sum 10 mil. array

iex(5)> :timer.tc(fn -> 1..10_000_000 |> Enum.sum() end)
{5, 50000005000000}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment