Skip to content

Instantly share code, notes, and snippets.

@alvises
Created January 13, 2019 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvises/3b16c146f60dbd766d1af9cf18c73319 to your computer and use it in GitHub Desktop.
Save alvises/3b16c146f60dbd766d1af9cf18c73319 to your computer and use it in GitHub Desktop.
Benchee benchmark of csv processing
lazy_csv_fn = fn ->
File.stream!("large.csv")
|> Stream.map(&String.trim(&1))
|> Stream.map(&String.split(&1, ","))
|> Stream.filter(fn
["Timestamp" | _] -> false
[_, "NaN" | _] -> false
[timestamp | _] ->
true
end) |> Enum.find(fn
[timestamp | _] ->
ts = String.to_integer(timestamp)
dt = DateTime.from_unix!(ts)
dt.year == 2015
end)
end
Benchee.run(%{
"lazy_csv" => lazy_csv_fn
}, time: 10, memory_time: 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment