Continuing the discussion from Performance - Best practices?
If they are iolists, then why do function_from_file
in eex
return binaries? https://github.com/idi-ot/eex_test
iex(1)> EExTest.fortune_html [a: "a", b: "b"]
"<!DOCTYPE html>\n<html>\n <head>\n <title>Fortunes</title>\n </head>\n <body>\n <table>\n <tr><th>id</th><th>message</th></tr>\n \n <tr><td>a</td><td>a</td></tr>\n \n <tr><td>b</td><td>b</td></tr>\n \n </table>\n </body>\n</html>\n"
I would’ve expected something like this
iex(3)> EExTest.custom_fortune_html [a: "a", b: "b"]
["<!DOCTYPE html>\n<html>\n <head>\n <title>Fortunes</title>\n </head>\n <body>\n <table>\n <tr><th>id</th><th>message</th></tr>\n",
["<tr><td>", "a", "</td><td>", "a", "</td></tr>", "<tr><td>", "b", "</td><td>",
"b", "</td></tr>"], " </table>\n </body>\n</html>\n"]
Some tests
# render small list
iex(6)> :timer.tc(fn -> Enum.each(1..100_000, fn _ -> EExTest.fortune_html([a: "a", b: "b"]) end) end)
{480068, :ok}
iex(7)> :timer.tc(fn -> Enum.each(1..100_000, fn _ -> EExTest.custom_fortune_html([a: "a", b: "b"]) end) end)
{279135, :ok}
# render empty list
iex(10)> :timer.tc(fn -> Enum.each(1..100_000, fn _ -> EExTest.fortune_html([]) end) end)
{144888, :ok}
iex(11)> :timer.tc(fn -> Enum.each(1..100_000, fn _ -> EExTest.custom_fortune_html([]) end) end)
{74700, :ok}
# render bigger list
iex(12)> data = Enum.map(1..1000, fn i -> {i, i} end)
iex(14)> :timer.tc(fn -> Enum.each(1..1_000, fn _ -> EExTest.custom_fortune_html(data) end) end)
{277821, :ok}
iex(15)> :timer.tc(fn -> Enum.each(1..1_000, fn _ -> EExTest.fortune_html(data) end) end)
{1078125, :ok}