eekenpiet

eekenpiet

Genetic Algorithms in Elixir: Error in task script from ch11 page 180 ebook version 1.0.2

After running a while the benchee test I got the following error: no function clause matching in Task.async/1
I wrote a script with async/3 which works on Elixir 1.17.3-otp27.

defmodule Pmap do
  def pmap(collection,func) do
    collection
    |> Enum.map(&Task.async(Pmap, func, [&1]))
    |> Enum.map(&Task.await(&1))
  end

  def expensive(x) do
    x = x * x
    :timer.sleep(1000)
    x
  end

  def inexpensive(x) do
    x * x
  end
end

data = for x <- 1..100, do: x

 Benchee.run(
  %{
    "pmap, expensive" => fn -> Pmap.pmap(data, :expensive) end,
    "pmap, inexpensive" => fn -> Pmap.pmap(data, :inexpensive) end,
    "map, expensive" => fn -> Enum.map(data, &(Pmap.expensive(&1))) end,
    "map, inexpensive" => fn -> Enum.map(data, &(Pmap.inexpensive(&1))) end
  },
  memory_time: 2
 )

"""
Name                        ips        average  deviation         median         99th %
map, inexpensive       983.51 K        1.02 μs  ±3697.41%        0.89 μs        1.35 μs
pmap, inexpensive        2.46 K      406.45 μs    ±15.08%      403.66 μs      557.18 μs
pmap, expensive       0.00200 K   501196.83 μs     ±0.07%   501063.27 μs   501968.52 μs
map, expensive        0.00002 K 50099628.15 μs     ±0.00% 50099628.15 μs 50099628.15 μs

Comparison:
map, inexpensive       983.51 K
pmap, inexpensive        2.46 K - 399.74x slower +405.43 μs
pmap, expensive       0.00200 K - 492932.24x slower +501195.82 μs
map, expensive        0.00002 K - 49273499.77x slower +50099627.13 μs

Memory usage statistics:

Name                      average  deviation         median         99th %
map, inexpensive          1.56 KB     ±0.00%        1.56 KB        1.56 KB
pmap, inexpensive        39.62 KB     ±0.60%       39.60 KB       39.68 KB
pmap, expensive          40.21 KB     ±3.01%       39.60 KB       42.02 KB
map, expensive            1.56 KB     ±0.00%        1.56 KB        1.56 KB

Comparison:
map, inexpensive          1.56 KB
pmap, inexpensive        39.62 KB - 25.36x memory usage +38.06 KB
pmap, expensive          40.21 KB - 25.73x memory usage +38.64 KB
map, expensive            1.56 KB - 1.00x memory usage +0 KB


"""

Where Next?

Popular Pragmatic Bookshelf topics Top

brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=&gt; (create-migration "guestbook") Execution error (Ill...
New
lirux
Hi Jamis, I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019. This test doesn’t pass for me: ...
New
herminiotorres
Hi @Margaret , On page VII the book tells us the example and snippets will be all using Elixir version 1.11 But on page 3 almost the en...
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
nicoatridge
Hi, I have just acquired Michael Fazio’s “Kotlin and Android Development” to learn about game programming for Android. I have a game in p...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
New
AufHe
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113. Iteration A1 - Seeing the list of prod...
New

Other popular topics Top

PragmaticBookshelf
Brace yourself for a fun challenge: build a photorealistic 3D renderer from scratch! In just a couple of weeks, build a ray tracer that r...
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
PragmaticBookshelf
From finance to artificial intelligence, genetic algorithms are a powerful tool with a wide array of applications. But you don't need an ...
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File &gt; New Rule: And select Deny, O...
New
New

Sub Categories: