 	 (println ": " elapsed# " millis")
 	 elapsed#))))
 
-;; todo - time rhs and lhs on different threads ?
 (defmacro faster [times lhs rhs]
-  `(< (millis ~times ~lhs) (millis ~times ~rhs)))
-
-(defrecord Value [v])
+  `(let [l# (millis ~times ~lhs) r# (millis ~times ~rhs)] (< l# r#)))
+
+(defmacro slower [times lhs rhs]
+  `(let [l# (millis ~times ~lhs) r# (millis ~times ~rhs)] (> l# r#)))
+
+(defmacro similar [times tolerance lhs rhs]
+  `(let [l# (millis ~times ~lhs) r# (millis ~times ~rhs)] (< (abs (- l# r#)) ~tolerance)))
 
 (defn ibm? []
   (.contains (.toLowerCase (System/getProperty "java.vm.vendor")) "ibm"))
+
+;;--------------------------------------------------------------------------------
+
+(defrecord Value [v])
 
 ;; (if (not (ibm?)) ;TODO - these assumptions do not hold true on IBM - maybe we should generate code accordingly ?
 ;;   (do

(ns org.dada.core.test-clojure
    (:use 
     [clojure test]
     )
    )

(set! *warn-on-reflection* true)

;; test the speed of various bits of clojure to help ascertain which way DADA should do things

(defmacro millis [times body]
  `(do
     (print (quote ~body))
     (let [start# (System/currentTimeMillis)]
       (do (dotimes [_# ~times] ~body) nil)

;;     (let [^{:tag (type (into-array Object []))} a (into-array Object [0])]
;;       (is (faster 100000000 (Value. 0) (.newInstance c a))))))

;; is accessing a record attribute using dot notation comparable in speed to dot notation method invocation ?
(deftest test-record-access-vs-pojo-method
  (let [^Value r (Value. 0)] (is (similar 100000000 30 (.v r)(.getClass r)))))

;; is accessing a record attribute faster by dot notation than by keyward ?
;; looks like it is currently 5x faster...
(deftest test-get
  (let [^Value v (Value. (Object.))] (is (faster 1000000000 (.v v) (:v v)))))

;; if we wrap the dot notation in a function, is it still faster ?
(deftest test-getter
  (let [^Value v (Value. (Object.)) f (fn [^Value v] (.v v))] (is (faster 1000000000 (f v) (:v v)))))

;; doseq nearly twice as fast

