2014-04-11 18:12 GMT+02:00 Alex Vzorov <alex.vzo...@gmail.com>:

> You could use a clojure agent <http://clojure.org/agents>, that would
> output your messages on a separate thread, one by one.
>
> (def *logger* (agent 0))
>
> (defn give-message [message]
>   (send *logger*
>         (fn [_ & [msg]] (println (format "%s: %s" (. time-format format (.
> (now) getTime)) msg)))
>         message))
>

I implemented it. Only changed *logger* to logger, because I got the
following message:
Warning: *logger* not declared dynamic and thus is not dynamically
rebindable, but its name suggests otherwise. Please either indicate
^:dynamic *logger* or change the name.

I would have expected that it would make the code slower, but it makes the
code actually faster. The more threads, the more positive result:
2 threads: 3% faster
4 threads: 5% faster
6 threads: 6% faster
7 threads: 8% faster
8 threads: 11% faster

What could be the reason that it makes the code faster? I find it even a
little bit strange, because the logging is only a small part of what I am
doing.

-- 
Cecil Westerhof

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to