Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make this clojure code run faster?
    primarykey
    data
    text
    <p>I have a version implemented in Lisp(SBCL) which runs under 0.001 seconds with 12 samples. However this version(in clojure) takes more than 1.1 secs. What should I do for making this code run as fast as original Lisp version?</p> <p>To make it sure, my numbers are not including times for starting repl and others. And is from time function of both sbcl and clojure.(Yes, my laptop is rather old atom based one)</p> <p>And this application is/will be used in the repl, not as compiled in single app, so running thousand times before benchmarking seems not meaningful.</p> <p>Oh, the fbars are like this: [[10.0 10.5 9.8 10.1] [10.1 10.8 10.1 10.7] ... ], which is Open-High-Low-Close price bars for the stocks.</p> <pre><code>(defn- build-new-smpl [fmx fmn h l c o] (let [fmax (max fmx h) fmin (min fmn l) fc (/ (+ c fmax fmin) 3.0) fcd (Math/round (* (- fc o) 1000)) frd (Math/round (* (- (* 2.0 c) fmax fmin) 1000))] (if (and (&gt; fcd 0) (&gt; frd 0)) [1 fmax fmin] (if (and (&lt; fcd 0) (&lt; frd 0)) [-1 fmax fmin] [0 fmax fmin])))) (defn binary-smpls-using [fbars] (let [fopen (first (first fbars))] (loop [fbars fbars, smpls [], fmax fopen, fmin fopen] (if (&gt; (count fbars) 0) (let [bar (first fbars) [_ h l c _] bar [nsmpl fmx fmn] (build-new-smpl fmax fmin h l c fopen)] (recur (rest fbars) (conj smpls nsmpl) fmx fmn)) smpls)))) </code></pre> <p>================================================</p> <p>Thank you. I managed to make the differences for 1000 iteration as 0.5 secs (1.3 secs on SBCL and 1.8 on Clojure). Major factor is I should have created fbars as not lazy but as concrete(?) vector or array, and this solves my problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload