Saturday, May 28, 2011

Some Clojure experiments

I was playing with the labrepl project, and doing some basic looping/recursion exercises.  In doing those exercises I wrote the following three functions to find the minimum and maximum values in a sequence:



I then wrote this timing function:



I ran 1000 iterations of that loop for each of the three functions. I was saddened to see how much slower the version that manipulates maps was compared to the other two. Here are the resulting average times:
  • minmax-1 => 0.3881 msecs
  • minmax-2 => 0.2400 msecs
  • minmax-3 => 1.8923 msecs
While I was disappointed by the performance of minmax-3, it was cool to see how fast destructuring is.  Especially considering that destructuring is very idiomatic Clojure and used frequently.

No comments: