Closed AlexBaranosky closed 11 years ago
This macro gives you the same effect as (some [foo] ....) but much faster, since it expands to a cond
.
(defmacro pred-cond
"Checks each predicate against the item, returning the corresponding
result if it finds a match, otherwise returning nil.
Assumes item to be a value, as it will get evaluated multiple times."
[item pred result & preds+results]
(cond (= pred :else ) result
(not (seq preds+results)) `(if (~pred ~item) ~result nil) ;; last condition, but no :else in the form
:else `(if (~pred ~item)
~result
(pred-cond ~item ~@preds+results))))
#'user/pred-cond
user=> (time (dotimes [i 100000] (pred-cond "a" string? true :else false)))
"Elapsed time: 2.504 msecs"
nil
This actually introduced a bug in boolean?
- just pushed a fix.
When running ./build
, it's easy to focus on the run time, and forget the actual test output - both these numbers should be as close to 0 as possible :-)
passed ... 146
failed ...0
pass rate ...100%
ok
0
run time: 17.895 secs
I was, apparently, running the wrong script to test, sorry. On Jan 23, 2013 4:21 AM, "Håkan Råberg" notifications@github.com wrote:
This actually introduced a bug in boolean? - just pushed a fix.
When running ./build, it's easy to focus on the run time, and forget the actual test output - both these numbers should be as close to 0 as possible :-)
passed ... 146 failed ...0 pass rate ...100%
ok 0
run time: 17.895 secs
— Reply to this email directly or view it on GitHubhttps://github.com/hraberg/shen.clj/pull/1#issuecomment-12593162.
Wow, the build went (very roughly) 17.5% faster with these changes!
On Wed, Jan 23, 2013 at 9:04 AM, Alex Baranosky < alexander.baranosky@gmail.com> wrote:
I was, apparently, running the wrong script to test, sorry. On Jan 23, 2013 4:21 AM, "Håkan Råberg" notifications@github.com wrote:
This actually introduced a bug in boolean? - just pushed a fix.
When running ./build, it's easy to focus on the run time, and forget the actual test output - both these numbers should be as close to 0 as possible :-)
passed ... 146 failed ...0 pass rate ...100%
ok 0
run time: 17.895 secs
— Reply to this email directly or view it on GitHubhttps://github.com/hraberg/shen.clj/pull/1#issuecomment-12593162.
Yep, Thanks! I think there's further speed gains to be found for sure..