diff --git a/sci b/sci index 51961ef2..689a4d01 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit 51961ef24817bb2e33a75946a74c493eac9bcbcf +Subproject commit 689a4d018f8f729ff79408b6a43aed631138b19a diff --git a/src/babashka/impl/clojure/core.clj b/src/babashka/impl/clojure/core.clj index d3a69ee4..bb7502af 100644 --- a/src/babashka/impl/clojure/core.clj +++ b/src/babashka/impl/clojure/core.clj @@ -6,6 +6,15 @@ (defn locking* [form bindings v f & args] (apply @#'locking/locking form bindings v f args)) +(defn time* + "Evaluates expr and prints the time it took. Returns the value of + expr." + [_ _ expr] + `(let [start# (. System (nanoTime)) + ret# ~expr] + (prn (str "Elapsed time: " (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs")) + ret#)) + (def core-extras {'file-seq file-seq 'agent agent @@ -18,5 +27,6 @@ 'shutdown-agents shutdown-agents 'slurp slurp 'spit spit + 'time (with-meta time* {:sci/macro true}) 'Throwable->map Throwable->map 'compare-and-set! compare-and-set!})