>
> I don't want to go out on a limb, having not looked at the Clojure STM
> implementation. However, I would bet that the costs are roughly equal.
> Even if Clojure was 50% slower, or 100% slower, the knowlege that you
> can spin up a large number of threads and not worry about deadlocks is
> ultimately more valuable.
>
It really depends on the problem. For instance in a Python program I wrote,
a genetic algorithm was doing some evolution as fast as it could. The
algorithm was heavily optimized, things that profiled slow were converted to
C though Cython.

I had a GUI that would display the current best individual every 5 seconds
(not every generation because there is a rendering cost). To keep the GUI
responsive, the evolution and the GUI would each run in their own thread.

Only 2 locks were required to implement this. A stop (lock protected)
variable would be set to True if the user through the GUI requested the
evolution to stop. The evolution thread would look at this variable before
computing the next generation (it would be unsafe to stop the evolution in
an half-finished state). A best (also lock protected) variable would be set
to the best individual after each new generation was computed.

A profiling run reveals that a whooping 25% of the execution time is spent
acquiring locks! Had I coded this in Clojure, there would not even be a
transaction! best would be asynchronously set and read and stop would be
useless as I could easily discard an half-finished computation of immutable
data.

I didn't convert the code yet to Clojure yet but it seems obvious that
Clojure's concurrency model would have been much faster.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to