Browse files

Added perf rules

  • Loading branch information...
1 parent 2cdf871 commit a6f0cf1aed9c32a22775725f13decfe57429eee6 @jonase committed Mar 19, 2012
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/jonase/kibit/rules/performance.clj
@@ -0,0 +1,5 @@
+(ns jonase.kibit.rules.performance
+ (:use [jonase.kibit.rules.util :only [defrules]]))
+(defrules rules
+ [(reduce + ?coll) (apply + ?coll)])
cgriego Nov 27, 2012

Going from my (limited) understanding of Clojure and going off the comment in the current version of this file compared against the style of ocmments in other files, I believe this rule might be backwards? As written it's recommending apply instead of reduce.

Edit from Paul // OhPauleez

This rule is correct. Addition for n-ary args is always faster than reduce, because addition is an n-ary operation (and it avoids unnecessary allocations).

user=> (time (reduce + (range 100)))
"Elapsed time: 1.42 msecs"
user=> (time (apply + (range 100)))
"Elapsed time: 0.807 msecs"

0 comments on commit a6f0cf1

Please sign in to comment.