Times are all from my laptop using the same test input and running on JDK 11.
Baseline smt-8: Execution time mean : 2.386019 sec
My first attempt: Execution time mean : 48.977240 ms
(defn smt-8'' [times-vec] (loop [res (transient []) pointer-1 0 pointer-2 7] (if-let [end-element (get times-vec pointer-2)] (let [start-element (get times-vec pointer-1) time-diff (- end-element start-element)] (recur (if (< time-diff 1000) (conj! res [(subvec times-vec pointer-1 (inc pointer-2)) time-diff]) res) (inc pointer-1) (inc pointer-2))) (persistent! res))))
(defn smt-8''' [times-vec] (binding [*unchecked-math* true] (loop [res (transient []) pointer-1 (int 0) pointer-2 (int 7)] (if-let [end-element (get times-vec pointer-2)] (let [start-element (get times-vec pointer-1) time-diff (- end-element start-element)] (recur (if (< time-diff 1000) (conj! res [(subvec times-vec pointer-1 (inc pointer-2)) time-diff]) res) (inc pointer-1) (inc pointer-2))) (persistent! res)))))
(defn smt-8'' [^"[J" times-arr] (binding [*unchecked-math* true] (loop [res (transient []) pointer-1 (int 0) pointer-2 (int 7)] (if (< pointer-2 (alength times-arr)) (let [start-element (aget times-arr pointer-1) end-element (aget times-arr pointer-2) time-diff (- end-element start-element)] (recur (if (< time-diff 1000) (conj! res [(mapv #(aget times-arr (+ pointer-1 %)) (range 8)) time-diff]) res) (inc pointer-1) (inc pointer-2))) (persistent! res)))))
(set! unchecked-math true)
globally, wrapping in a binding like I did does nothing, since it needs to be set at compile time. My measurement were with it set globally.
Times are all from my laptop using the same test input and running on JDK 11.
Baseline smt-8: Execution time mean : 2.386019 sec
My first attempt: Execution time mean : 48.977240 ms
With performance tweaks: Execution time mean : 23.567174 ms Less idiomatic as I'm using an array: Execution time mean : 1.678226 ms All my solutions produce exactly the same result where it includes both the list of elements and their time difference.