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

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
AleksandrKudashkin
On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
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
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
New
Henrai
Hi, I’m working on the Chapter 8 of the book. After I add add the point_offset, I’m still able to see acne: In the image above, I re...
New
ggerico
I got this error when executing the plot files on macOS Ventura 13.0.1 with Python 3.10.8 and matplotlib 3.6.1: programming_ML/code/03_...
New
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
DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
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
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
NewsBot
Node.js v22.14.0 has been released. Link: Release 2025-02-11, Version 22.14.0 'Jod' (LTS), @aduh95 · nodejs/node · GitHub
New

Sub Categories: