4 ms·
All the clojure examples test linked lists! The first example lets lazy evaluation of the random numbers leak into the timing, toss a (dorun tmp) before the ti
by skew 15y ago
All the clojure examples test linked lists!
The first example lets lazy evaluation of the random numbers leak into the timing, toss a (dorun tmp) before the timing for a little more sense.
The type annotation ^doubles is useless - it's telling Clojure to expect the definition to get an array of doubles, but then binds it to the same old linked lists.
- rbanffy 15y agoI was going to point this out. As always, if you aim for high performance, you should know your data structures. And use the right ones.
- bretthoerner 15y agoCan you fix his code and paste it? Why not have him run the bench and post it as an update?
- rjn945 15y agoBased on the work of a previous commenter, I posted this code in the blog comments: (defn add-rands [] (let [ds (double-array 30000000)] (dotimes [i 30000000] (aset ds i (Math/random))) (time (areduce ds i res 0.0 (+ res (aget ds i)))))) This adds 30,000,000 numbers in 73ms on my machine. His Lush code added 30,000,000 in 180ms. I estimate my computer is twice as fast as his, putting them on par. Hopefully he will run the code so we can see all the run times on the same machine. (I never could get his Lush code running.) Of course, the Clojure code here is fairly involved to do some basic stuff, but if you did things like this often it would not be hard to add some nice syntactic sugar over it.