Idiomatic Clojure without sacrificing performance
On Slack I gave it a go as well, my naïve idiomatic solution turned out to be 50x faster from the get go.<p>Times are all from my laptop using the same test input and running on JDK 11.<p>Baseline smt-8: Execution time mean : 2.386019 sec<p>My first attempt: Execution time mean : 48.977240 ms<p><pre><code>    (defn smt-8&#x27;&#x27; [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 (&lt; time-diff 1000)
               (conj! res [(subvec times-vec pointer-1 (inc pointer-2))
                           time-diff])
               res)
             (inc pointer-1)
             (inc pointer-2)))
          (persistent! res))))
</code></pre>
With performance tweaks: Execution time mean : 23.567174 ms<p><pre><code>    (defn smt-8&#x27;&#x27;&#x27; [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 (&lt; time-diff 1000)
                 (conj! res [(subvec times-vec pointer-1 (inc pointer-2))
                             time-diff])
                 res)
               (inc pointer-1)
               (inc pointer-2)))
            (persistent! res)))))
</code></pre>
Less idiomatic as I&#x27;m using an array: Execution time mean : 1.678226 ms<p><pre><code>    (defn smt-8&#x27;&#x27; [^&quot;[J&quot; times-arr]
      (binding [*unchecked-math* true]
        (loop [res (transient []) pointer-1 (int 0) pointer-2 (int 7)]
          (if (&lt; 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 (&lt; time-diff 1000)
                 (conj! res [(mapv #(aget times-arr (+ pointer-1 %)) (range 8))
                             time-diff])
                 res)
               (inc pointer-1)
               (inc pointer-2)))
            (persistent! res)))))
</code></pre>
All my solutions produce exactly the same result where it includes both the list of elements and their time difference.