<< Back to previous view

[CLJ-784] Update min/max functions to take advantage of primitive math Created: 29/Apr/11  Updated: 01/Mar/13  Resolved: 26/May/11

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.3
Fix Version/s: Release 1.3

Type: Enhancement Priority: Major
Reporter: Luke VanderHart Assignee: Luke VanderHart
Resolution: Completed Votes: 0
Labels: None

Attachments: Text File 0784-min-max-take-3.patch     Text File fast_min_max_no_contagion.patch     Text File fast_min_max.patch    
Patch: Code
Approval: Ok


Currently, the min and max functions are quite slow, since they don't take advantage of new primitive math.

Implement them in the same manner in which other primitive math functions are implemented for efficiency.

Comment by Luke VanderHart [ 29/Apr/11 3:17 PM ]

This patch creates inline versions of min and max, combined with overloaded implementations in c.l.Numbers. It is over an order of magnitude faster using a test like this one (from 19 seconds to 1.2 seconds on my machine):

(time (loop [a 0 b 10 c 5]
            (if (< a 1000000000)
                (recur (inc a) (min b c) (max c b)))))

There are two patches. One is contagious, but returns primitives for (long, double) input. The other is not contagious and returns primitives only for (long,long) and (double,double) args, but is still substantially faster than the original version.

Comment by Stuart Halloway [ 06/May/11 10:11 AM ]

The May 6 "take 3" patch eliminates a few contagions that were hiding in the earlier patch, and is hopefully good to go.

Generated at Sun Jan 21 05:13:12 CST 2018 using JIRA 4.4#649-r158309.