Sean/Stuart/Others -

My apologies to the group. I found out why my Clojure code runs slower
than Java.

The Java code uses the setFetchSize() method to retrieve data in
batch:

            myResultSet.setFetchSize(1000);
            myResultSet.setFetchDirection(ResultSet.FETCH_FORWARD);

Without the above optimization the Java code performs identical to the
Clojure code.

The setFetchSize() makes a huge difference in performance. For
retrieval of 100,000 records I found that it runs x10 faster.

Sean - could you let me know how I can specify the fetch size in
clojure.java.jdbc?

I use the below utility function exec-query to execute SQL queries.
How should I specify the parameters for the prepared statement?

(ns ..
   (require [clojure.contrib.sql :as sql])
    ..)

(defn exec-query
  "Execute query"
  ([query-str bvs]
  (sql/with-connection dbconn
    (sql/with-query-results recs (into [query-str] bvs)
        (doall recs)))))

Thanks
Shoeb

On Aug 7, 10:48 am, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:
> Hi Shoeb,
>
> At this point, we probably need more data to give a meaningful answer.
> Different core data structures and different coding conventions can mean
> that "the same code" in Clojure and Java will behave quite differently.
>
> Try profiling your Clojure code with a Java profiler such as VisualVM (free)
> or YourKit (commercial). That will show you exactly which functions are
> taking the most time. Then we may be able to recommend ways to eliminate the
> most expensive calls in the Clojure version.
>
> -Stuart Sierra
> clojure.com

-- 
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

Reply via email to