Does dotimes force evaluation?, if so, then the Clojure version is about twice as fast for me... which would be nice to finally find a good dynamic programming language that is also nice and fast :-)
the code I tested is this: (def HHQ [{:id 1956, :firstname "Piet", :lastname "Puk", :programming_skills #{:java, :php, :closure}} {:id 2000, :firstname "Blaat", :lastname "Aap", :programming_skills #{:java, :php, :python}} {:id 2020, :firstname "Jaap", :lastname "Klaas", :programming_skills #{:cobol, :php, :skala}}]) (time (dotimes [n 1000000] (into {} (for [x HHQ :when ((x :programming_skills) :java)] [(x :id) (str (x :firstname) " " (x :lastname))])))) vs the python version HHQ = [{'id': 1956, 'firstname': "Piet", 'lastname': "Puk", 'programming_skills': set(['java', 'php', 'closure'])}, {'id': 2000, 'firstname': "Blaat", 'lastname': "Aap", 'programming_skills': set(['java', 'php', 'python'])}, {'id': 2020, 'firstname': "Jaap", 'lastname': "Klaas", 'programming_skills': set(['cobol', 'php', 'skala'])}] import time start = time.time() for i in range(1000000): dict([(x['id'], (x['firstname'] + " " + x['lastname'])) for x in HHQ if 'java' in x['programming_skills']]) end = time.time() print end - start On 14 okt, 19:09, Chris Perkins <chrisperkin...@gmail.com> wrote: > On Oct 14, 11:54 am, Henk <henkp...@gmail.com> wrote: > > > (I did some small benchmarks on this), while the list comprehension > > itself is much faster than python... > > Not an answer to your question, but: depending on what you mean by > "much faster", there is a good chance that you measured the clojure > for expression doing nothing. You should wrap it in a doall or dorun > to get a proper timing (like a generator in Python). > > Eg: for me, the following are almost exactly the same speed (~45ms): > > user=> (time (dorun (for [i (range 100000)] [i (* i i)]))) > "Elapsed time: 45.965679 msecs" > > C:\Users\chris>python -m timeit "[(i,i*i) for i in range(100000)]" > 10 loops, best of 3: 45.5 msec per loop > > - Chris -- 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