Skip to content

Instantly share code, notes, and snippets.

@alvises
Created April 9, 2019 11:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvises/54451c50ac0b9bafe0c932e4b2240b32 to your computer and use it in GitHub Desktop.
Save alvises/54451c50ac0b9bafe0c932e4b2240b32 to your computer and use it in GitHub Desktop.
Elixir File.stream! lines vs chunks
lines = File.stream!("file_path")
chunks = File.stream!("file_path",[],2_048)
hash_fun = fn enum ->
enum
|> Enum.reduce(:crypto.hash_init(:sha),&(:crypto.hash_update(&2, &1)))
|> :crypto.hash_final()
|> Base.encode16()
end
Benchee.run(%{
"lines" => fn ->
lines
|> hash_fun.()
end,
"chunks" => fn ->
chunks
|> hash_fun.()
end
},
time: 10,
memory_time: 2
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment