Playing with Processes in Elixir

I wanted to dip my toes into elixirs processes just a bit. So I figured I'd use 100,000 processes to generate some fake data for a CSV. I also wanted to benchmark the difference between single process function and then doing it in parallel.

To generate the fake data I used the faker library.
To benchmark the two methods I used benchfella.

For my single process function I just used a comprehension to build a list of fake list data.

 def generate_data do
    for x <- 1..100_000, do: [Faker.Name.name, Faker.Address.street_address, Faker.Company.bs]
  end

For the multiprocess function I built a map of 100k processes and collected their pids, I then received the message from each pid.

def p_generate_data do  
    me = self
    Enum.map(1..100_000, fn (_) ->
      spawn_link fn -> (send me, {self, [Faker.Name.name, Faker.Address.street_address, Faker.Company.bs]}) end
    end)
    |> Enum.map(fn (pid) ->
      receive do { ^pid, result } -> result end
    end)
  end

Finally I wrote the 2 bench tests.

defmodule SingleBench do  
  use Benchfella

  bench "generate 100k lists of data through Faker" do
    Faker.start
    ProcessPlay.WriteCSV.generate_data
  end
end

defmodule ParallelData do  
  use Benchfella

  bench "generate 100k lists of data in parallel through faker" do
    Faker.start
    ProcessPlay.WriteCSV.p_generate_data
  end
end  

Here is the results of the two tests.

Compiled lib/process_play/write_csv.ex  
Generated process_play app  
Settings:  
  duration:      1.0 s

## SingleBench
[16:36:36] 1/1: generate 100k lists of data through Faker

Finished in 9.71 seconds

## SingleBench
generate 100k lists of data through Faker           1   9613343.00 µs/op

Settings:  
  duration:      1.0 s

## ParallelData
[16:37:39] 1/1: generate 100k lists of data in parallel through faker

Finished in 5.47 seconds

## ParallelData
generate 100k lists of data in parallel through faker           1   5380309.00 µs/op  

Pretty decent improvement in speed.

Full project here