Skip to content

Commit

Permalink
Added perf rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jonase committed Mar 19, 2012
1 parent 2cdf871 commit a6f0cf1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 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)])

This comment has been minimized.

Copy link
@cgriego

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"
4950
user=> (time (apply + (range 100)))
"Elapsed time: 0.807 msecs"
4950

0 comments on commit a6f0cf1

Please sign in to comment.