On Wed, Apr 20, 2011 at 11:21 AM, Michael Golovanov <mike.golova...@gmail.com> wrote:
> My question is how to find performance bottlenecks in Clojure > applications. > Second question is about my code. Where are the problem? > May be this is > 1. Incorrect execution time measuring procedure > 2. Bad algorithm > 3. Slow input/output (read from System.in stream/ printing to > System.out) in Clojure > One rule of thumb when performance tuning clojure code is to (set! *warn-on-reflection* true) at the top of your code. In your case, there is one reflection warning in your loop that I bet will get a large part of your performance back. Also, your recursive call is in tail-position, so you can use recur which is basically compiled down to a goto rather than a function call. This will save stack and probably run faster. How does the following work for you? (defn getNextInt [#^Scanner scanner term f x] (if (not= x nil) (apply f [x])) (let [val (. scanner nextInt)] (if (not= val term) (recur scanner term f val)))) -- 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