For my own needs, I wrote a macro 'timings' - see Timing expressions and 
comparing results:
https://groups.google.com/d/msg/clojure/o8pOLc6uxQQ/bui7sJ-F5_wJ
Code and examples are here:
https://gist.github.com/fsodomka/5890711

Your examples on my machine with Clojure 1.5.1:
(report
  (let [x 2 y [0 1 2 3 4]]
    (timings 10000000
      (remove #{x} y)
      (remove #(= % x) y)
      (remove #(== % x) y)
      (remove #(.equals % x) y))))

|                                                                        
:expr |           :time | :ratio | :perc |
|----------------------------------------------------------------+---------------+--------+-------|
|      (remove (fn* [p1__435#] (== p1__435# x)) y)   |  28.164219 |    1.0 
  |  3.84 |
| (remove (fn* [p1__436#] (.equals p1__436# x)) y) |  28.310134 |   1.01  
|  3.86 |
|       (remove (fn* [p1__434#] (= p1__434# x)) y)     |  29.038815 |   
1.03  |  3.96 |
|                                                       (remove #{x} y) | 
733.326342 |  26.04 | 100.0 |

Using set is 26 times slower than any other way and I would probably pick 
== for number comparison.

(report
  (let [a (int-array 10)]
    (timings 10000000
      (aset a 1 2)
      (aset-int a 1 2))))

|            :expr |     :time | :ratio | :perc |
|------------------+-----------+--------+-------|
|     (aset a 1 2) | 16.062221 |    1.0 |  4.47 |
| (aset-int a 1 2) | 359.22866 |  22.36 | 100.0 |

aset-int is 22x slower than aset.

I would definitely find some resource on performance useful. On the other 
side, things change and many recommendations are not valid anymore:
http://gnuvince.wordpress.com/2009/05/11/clojure-performance-tips/
- destructuring is faster ;-)
- spliting (+ 2 4 5) to (+ 2 (+ 4 5)) isn't needed
- etc.
Performance changes with versions of Clojure.

Libraries to consider:
https://github.com/hugoduncan/criterium
https://github.com/davidsantiago/perforate

Frantisek

On Sunday, July 14, 2013 10:15:04 AM UTC+2, Marc Dzaebel wrote:
>
> I'm often in need of performance comparisons/recommendations about 
> different ways to code the same usecases. E.g.
>
> (time(let [x 2 y [0 1 2 3 4]] (dotimes [_ 10000000] (remove *#{x}*y))))     
> ;~950 ms
> (time(let [x 2 y [0 1 2 3 4]] (dotimes [_ 10000000] (remove *#(= % x)*y)))) 
> ;~150 ms
>
> (time(let [a (int-array 10)]  (dotimes [_ 10000000] (*aset *a 1 
> 2))))        ;~7 ms
> (time(let [a (int-array 10)]  (dotimes [_ 10000000] (*aset-int *a 1 
> 2))))    ;~430 ms
>
> I'd recommend to gather such information at a central place in a more 
> systematic way. So I wonder:
>
>    - where to place such information 
> (Wiki?)<http://en.wikibooks.org/wiki/Clojure_Programming>
>    - whether this information is of use 
>    - whether you have more recommendations regarding performance or the 
>    form, advices are presented
>    
> *Thanks, Marc*
>

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to