Skip to content

Instantly share code, notes, and snippets.

@jdfrens
Last active April 27, 2018 14:44
Show Gist options
  • Save jdfrens/f754ae6c048196bbce47776e31ae6925 to your computer and use it in GitHub Desktop.
Save jdfrens/f754ae6c048196bbce47776e31ae6925 to your computer and use it in GitHub Desktop.
The results may surprise you!
defmodule ExperimentBench do
use Benchfella
@list Enum.to_list(1..500_000) |> Enum.map(&to_string/1)
bench "IO.puts" do
file = File.open!("/tmp/puts.txt", [:write])
Enum.each(@list, &(IO.puts file, &1))
File.close(file)
end
bench "IO.write join" do
file = File.open!("/tmp/write-join.txt", [:write])
IO.write file, Enum.join(@list, "\n")
File.close(file)
end
bench "IO.write interspersed" do
file = File.open!("/tmp/write-intersperse.txt", [:write])
IO.write file, Enum.intersperse(@list, "\n")
File.close(file)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment