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
"""
Popular Pragmatic Bookshelf topics
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’.
In particula...
New
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159
When I execute the command:
user=> (create-...
New
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
Page 28: It implements io.ReaderAt on the store type.
Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt?
...
New
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
Title: Intuitive Python: docker run… denied error (page 2)
Attempted to run the docker command in both CLI and Powershell
PS C:\Users\r...
New
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
This is as much a suggestion as a question, as a note for others.
Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I t...
New
Other popular topics
Hello Devtalk World!
Please let us know a little about who you are and where you’re from :nerd_face:
New
Reading something? Working on something? Planning something? Changing jobs even!?
If you’re up for sharing, please let us know what you’...
New
Learn from the award-winning programming series that inspired the Elixir language, and go on a step-by-step journey through the most impo...
New
Which, if any, games do you play? On what platform?
I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
There’s a whole world of custom keycaps out there that I didn’t know existed!
Check out all of our Keycaps threads here:
https://forum....
New
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
New
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
Will Swifties’ war on AI fakes spark a deepfake porn reckoning?
New
Hello,
I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /emacs
- /haskell
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /html
- /opensuse
- /zig
- /deepseek
- /centos
- /php
- /scala
- /react-native
- /lisp
- /sublime-text
- /textmate
- /nixos
- /debian
- /agda
- /deno
- /django
- /kubuntu
- /arch-linux
- /nodejs
- /spring
- /ubuntu
- /revery
- /manjaro
- /lua
- /julia
- /diversity
- /markdown
- /slackware









