Last active
April 27, 2018 14:44
-
-
Save jdfrens/f754ae6c048196bbce47776e31ae6925 to your computer and use it in GitHub Desktop.
The results may surprise you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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