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

  # The :binary functions split and replace are not nifs.
  def slurp(path) do
    bin = File.read!(path)
    search = :binary.compile_pattern(<<"\n">>)
    new_bin = :binary.replace(bin,search,<<"">>,[:global])
    :erlang.byte_size(bin) - :erlang.byte_size(new_bin)
  end

Timing Results

File slurping with only NIF functions from :binary

NIF functions from :binary with file chunking

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