Is it possible to get only the time with the function 'time'

82 views
Skip to first unread message

Goldritter

unread,
Mar 28, 2012, 3:32:12 PM3/28/12
to Clojure
I wanted to aks if it is possible to get only the passed milliseconds
from the function 'time' without the sentence "Elapsed time: 0.119
msecs". I would only need the 0.119 and best as a number and not as a
String.
Or have I to write a function which extracts the number out of the
String?

Moritz Ulrich

unread,
Mar 28, 2012, 3:34:47 PM3/28/12
to clo...@googlegroups.com
You should use java interop for this:

(java.lang.System/currentTimeMillis)

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

--
Moritz Ulrich

Marcus Lindner

unread,
Mar 28, 2012, 3:40:18 PM3/28/12
to clo...@googlegroups.com
Something like this?

(tracktime [f]
let [ start (System/currentTimeMillis)
result (f)
end (System/currentTimeMillis)]
(vector result (- end start)))

Moritz Ulrich

unread,
Mar 28, 2012, 3:45:06 PM3/28/12
to clo...@googlegroups.com
Looks like it could work. If you want to track even short times, use
System/nanoTime. If you're interested, take a look at the
implementation of `time':
https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L3424

--
Moritz Ulrich

Marcus Lindner

unread,
Mar 28, 2012, 3:48:02 PM3/28/12
to clo...@googlegroups.com
Thanks.
I will try it.
Reply all
Reply to author
Forward
0 new messages