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
Hi @venkats,
It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
New
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
Title: Web Development with Clojure, Third Edition, vB17.0 (p9)
The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
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
When trying to run tox in parallel as explained on page 151, I got the following error:
tox: error: argument -p/–parallel: expected one...
New
Hi,
I am getting an error I cannot figure out on my test.
I have what I think is the exact code from the book, other than I changed “us...
New
The allprojects block listed on page 245 produces the following error when syncing gradle:
“org.gradle.api.GradleScriptException: A prob...
New
Getting an error when installing the dependencies at the start of this chapter:
could not compile dependency :exla, "mix compile" failed...
New
I just bought this book to learn about Android development, and I’m already running into a major issue in Ch. 1, p. 20: “Update activity...
New
Other popular topics
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
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
Think Again 50% Off Sale »
The theme of this sale is new perspectives on familiar topics.
Enter coupon code ThinkAgain2021 at checkout t...
New
Create efficient, elegant software tests in pytest, Python's most powerful testing framework.
Brian Okken @brianokken
Edited by Kat...
New
Saw this on TikTok of all places! :lol:
Anyone heard of them before?
Lite:
New
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
Author Spotlight
Mike Riley
@mriley
This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New
Will Swifties’ war on AI fakes spark a deepfake porn reckoning?
New
I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc.
However, I don’t...
New
If you’re getting errors like this:
psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
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
- /elm
- /flutter
- /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
- /diversity
- /julia
- /lua
- /markdown
- /v









