Hi all. I am trying to figure out what the effect of the agent-function is on the efficiency of concurrency. Here is something I do not really understand. I've a fibonacci function and a simple multiplication, both are wrapped in their respective dotimes 100k loop.
However, on this 4core machine, the fib behaves as I would expect when I scale up the number of threads, while the multiplication barely seems to benefit from the 4 cores. The only difference I see between the two functions is that the fib is recursive, but I am not quite sure why that would matter. Can anyone shine a light? (defn fib [n] "nonoptimized fib" (if (<= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))) (defn loopfib [n] (dotimes [i 100000] (fib n))) (defn loopmult [n] (dotimes [i 100000] (* n n n n n 5000 5000 4000 3000 9000))) (dotimes [t 12] (println "threads: " t) (time (let [agents (for [i (range t)] (agent 4))] (do (doseq [a agents] (send-off a loopfib)) (apply await agents)))) (time (let [agents (for [i (range t)] (agent 4))] (do (doseq [a agents] (send-off a loopmult)) (apply await agents))))) result: threads: 0 "Elapsed time: 0.279713 msecs" "Elapsed time: 0.38143 msecs" threads: 1 "Elapsed time: 205.458949 msecs" "Elapsed time: 209.625273 msecs" threads: 2 "Elapsed time: 205.610849 msecs" "Elapsed time: 357.785344 msecs" threads: 3 "Elapsed time: 205.05658 msecs" "Elapsed time: 401.39515 msecs" threads: 4 "Elapsed time: 221.140317 msecs" "Elapsed time: 469.746969 msecs" threads: 5 "Elapsed time: 309.472848 msecs" "Elapsed time: 597.872393 msecs" threads: 6 "Elapsed time: 336.087848 msecs" "Elapsed time: 714.874749 msecs" threads: 7 "Elapsed time: 382.883045 msecs" "Elapsed time: 846.888746 msecs" threads: 8 "Elapsed time: 442.588196 msecs" "Elapsed time: 960.687669 msecs" threads: 9 "Elapsed time: 478.862175 msecs" "Elapsed time: 1094.892017 msecs" threads: 10 "Elapsed time: 514.380769 msecs" "Elapsed time: 1219.219582 msecs" threads: 11 "Elapsed time: 580.265387 msecs" "Elapsed time: 1361.204858 msecs" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---