Any idea why thread is slower than go blocks
?
Grab a copy of yourkit and profile it.
That is a meaningless question
@alexmiller what am I missing?
Everything? I’m not even sure where to start
This code is nonsensical. Starting from an actual meaningful problem would be a good first step.
I am trying to come up with a simple code snippet that demonstrates how go blocks work
thread and go are for different purposes, and that is a more meaningful decision dimension than perf
I know that
My purpose is didactic
Then start from a meaningful problem
I did that
What is it?
Writing in parallel to a db
We’ll go blocks shouldn’t block, so that’s a bad problem to demonstrate go blocks
I know
I don’t know how to help you
Can you think of a simple way to demonstrate that go blocks don’t have a perfomance hit?
Go blocks are a process and communication tool. They are about organizing the running parts of your program. Performance is not imo a concern that enters that equation
Spawn threads is slower then "spawn" go blocks
(time
(dotimes [i 1e6]
(async/go i)))
"Elapsed time: 476.882375 msecs"
=> nil
(time
(dotimes [i 1e6]
(async/thread i)))
"Elapsed time: 1285.235322 msecs"
As Alex said, it isn't irrelevant, once they have different proposes and on both proposes, the performance implications arent related with "spawn" cost.