clojure - Print execution time of function in seconds? -


(time(get_report)) 

gives me "elapsed time 32038 ms". want seconds, not ms. how can accomplish in clojure?

i want print "report took 32 seconds".

update on how have now:

(defmacro time   "evaluates expr , prints time took.  returns value of    expr." {:added "1.0"} [expr] `(let [start# (. system (nanotime))      ret# ~expr]  (prn (str "report print time: " (/ (double (- (. system (nanotime))   start#)) 1000000000.0) " secs"))))  (time(get_report)) 

this gather_report function:

(defn gather_report []  (def list_of_isbns (split_isbns "src/clj_amazon/isbn_list.txt")) (get_title_and_rank_for_all_isbns list_of_isbns) ) 

this standard definition:

(defmacro time   "evaluates expr , prints time took.  returns value of  expr."   {:added "1.0"}   [expr]   `(let [start# (. system (nanotime))          ret# ~expr]      (prn (str "elapsed time: " (/ (double (- (. system (nanotime)) start#)) 1000000.0) " msecs"))      ret#)) 

note division form? divide 1000 convert seconds. can change message aswell:

(defmacro time   "evaluates expr , prints time took.  returns value of  expr."   {:added "1.0"}   [expr]   `(let [start# (. system (nanotime))          ret# ~expr]      (prn (str "report print time: " (/ (double (- (. system (nanotime)) start#)) 1000000000.0) " secs"))      ret#)) 

the best way find source of clojure docs function, , follow the" source" link.

and why don't use def inside function definition:

(defn test-fn []      (def some-val 20)     (* some-val some-val)  (test-fn)  (println some-val)  ; prints 20!  

def creates global value. don't want that! use let instead limit scope:

(defn test-fn []      (let [some-val 20]         (* some-val some-val))  

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -