Ok, here is a full macro with example usage and example format.
Note that it overlaps values, so higher time units are required.
(defmacro time2
[fmt expr]
(import '(java.text SimpleDateFormat) '(java.util Date TimeZone))
`(let [start# (System/currentTimeMillis)
ret# ~expr stop# (- (System/currentTimeMillis) start#)]
(prn (.format (doto (SimpleDateFormat. ~fmt) (.setTimeZone
(TimeZone/getTimeZone "GMT:00")) )
(Date. stop#)))
ret#))
(time2 "H'hr.' m'min.' s'sec.' S'msec.'" (Thread/sleep 1000))
Btw. How the import above will behave? Only for the first time the
macro is created or always on time2 call?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en