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

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
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex&gt; product = %Product{} %Pento....
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New

Other popular topics Top

PragmaticBookshelf
Write Elixir tests that you can be proud of. Dive into Elixir’s test philosophy and gain mastery over the terminology and concepts that u...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
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
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
CommunityNews
Open-source implementation of the classic GTA engine now running directly in your browser. Experience the reVC technology demo on DOS.Zon...
New
xiji2646-netizen
Woke up to this today: Claude Code’s complete source code exposed via npm source map. Not a snippet. All 512,000 lines. 1,900 TypeScript ...
New

Sub Categories: