Created
August 21, 2011 17:04
-
-
Save swannodette/1160849 to your computer and use it in GitHub Desktop.
vecmatch.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def IntArray (class (int-array []))) | |
(defmethod vtest-inline ::ints | |
[_ ocr] `(instance? IntArray ~ocr)) | |
(defmethod vnth-inline ::ints | |
[_ ocr i] `(aget ~ocr ~i)) | |
;; 60ms | |
(let [x (int-array [1 2 3])] | |
(dotimes [_ 10] | |
(time | |
(dotimes [_ 1e7] | |
(match [x] | |
[([_ _ 2] :vec ::ints)] :a0 | |
[([1 1 3] :vec ::ints)] :a1 | |
[([1 2 3] :vec ::ints)] :a2))))) | |
(defmethod vtest-inline ::bits | |
[_ ocr] `(instance? Long ~ocr)) | |
(defmethod vnth-inline ::bits | |
[_ ocr i] `(bit-shift-right | |
(bit-and ~ocr (bit-shift-left 1 ~i)) ~i)) | |
;; 50ms | |
(let [x 5] | |
(dotimes [_ 10] | |
(time | |
(dotimes [_ 1e7] | |
(match [x] | |
[([_ _ 1 1] :vec ::bits)] :a0 | |
[([1 0 1 _] :vec ::bits)] :a1))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment