Beatwc

Goofing around to see if we can beatwc in Elixir

View the Project on GitHub bbense/beatwc

Beating System.cmd("wc",["-l", file]) with native Elixir code

Know the Enemy

Naive File.Stream!

First pass at slurp with :binary functions

File slurping with only NIF functions from :binary

NIF functions from :binary with file chunking

  def chunkynifs(path, chunksize \\ @chunk_size) do
    File.stream!(path, [], chunksize)
    |> Enum.reduce(0, fn(chunk, total) -> total + count(chunk) end)
  end

  defp count(binary) do
    search = :binary.compile_pattern(<<"\n">>)
    :erlang.length(:binary.matches(binary, search))
  end

Timing Results

NIF functions from :binary with file chunking and parallel task execution