Clojure JIRA
http://dev.clojure.org/jira/secure/IssueNavigator.jspa?reset=true&jqlQuery=project+%3D+10079+AND+labels+%3D+patch
An XML representation of a search requesten-us4.464925-07-2011[MCOMB-4] Performance enhancement for sorted-numbers?
http://dev.clojure.org/jira/browse/MCOMB-4
math.combinatorics<p>Hi,</p>
<p>Came upon this as I was trying to improve performance. The implementation of sorted-numbers? (only used by permutations) is:<br/>
(defn- sorted-numbers?<br/>
"Returns true iff s is a sequence of numbers in non-decreasing order"<br/>
<span class="error">[s]</span><br/>
(and (every? number? s)<br/>
(every? (partial apply <=) (partition 2 1 s))))</p>
<p><= and similar operators are variadic, so partitioning into pairs is unneeded.<br/>
(apply <= s) is a lot faster, but breaks for empty sequences, so an additional check is needed.</p>
<p>The implementation can be changed to:</p>
<p>(and (every? number? s)<br/>
(or (empty? s) (apply <= s)))</p>
<p>I benched this to be 10 to 15 times faster. A regression test with test.check was done to verify that the behaviour was not changed under any input.<br/>
A patch is also included.</p>
<p>Cheers,</p>
<p>Daniel</p>MCOMB-4Performance enhancement for sorted-numbers?EnhancementTrivialResolvedCompletedMark EngelbergDaniel MarjenburghSat, 12 Jul 2014 07:46:48 -0500Sat, 19 Jul 2014 17:07:57 -0500Sat, 19 Jul 2014 17:07:57 -050001<p>Thanks for the submission. I don't know whether Mark would be interested in taking the test.check regression test you developed, too, but if you would be willing to share it as a patch, it might be considered for inclusion as well.</p><p>Hm, I don't know how I could include the regression test as a patch. Because:<br/>
1) The current project does not use external libraries or Leiningen (yet). How do I add dependencies when not using Leiningen?<br/>
2) I tested the old implementation vs the new one with generated inputs. If the old implementation is gone, there's no test to add...</p><p>Since this function is only called once at the beginning of the permutations process, on a sequence that is usually 10 or fewer items, I can't imagine this improvement will have any meaningful impact on the overall running time of the permutations algorithm. Nevertheless, it's an improvement, so I've gone ahead and added it.</p>ApprovalAcceptedGlobal RankPatchCode[MCOMB-1] math.combinatorics README should be updated to conform to contrib standard
http://dev.clojure.org/jira/browse/MCOMB-1
math.combinatorics<p>As per Sean Corfield's suggestion here: <a href="https://groups.google.com/forum/?fromgroups=#!searchin/clojure-dev/math/clojure-dev/p5oz42gR_sk/cesMHO9cDWEJ">https://groups.google.com/forum/?fromgroups=#!searchin/clojure-dev/math/clojure-dev/p5oz42gR_sk/cesMHO9cDWEJ</a><br/>
the math.combinatorics README.md should be updated to be more useful, especially to newbies.</p>MCOMB-1math.combinatorics README should be updated to conform to contrib standardEnhancementTrivialResolvedCompletedMark EngelbergChristian RomneyMon, 17 Sep 2012 07:00:39 -0500Mon, 17 Sep 2012 11:35:57 -0500Mon, 17 Sep 2012 11:35:57 -050000<p>Patch applied.</p>Global RankPatchCode