Is it possible to cast the Elapsed Time function to Integer?

I have the following function:

(def elapsedtime (with-out-str (time (run-my-function))))

and I was wondering if is possible to store only the integer value of the time, as I can only store a String at the moment....

Any suggestion? Thanks a lot


So I did use this:
  (defmacro nsecs
  `(let [start# (. System (nanoTime))]
     (- (. System (nanoTime)) start#)))

And then modified this:

(def elapsedtime (nsecs (run-my-function argument1 argument2)))

but doesn't work, what am I doing wrong?

"Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Wrong number of args (1) passed to: main$fn--105$nsecs"


Instead of extracting this value from a string, let's take a look at the source of the time macro.

(defmacro time
  "Evaluates expr and prints the time it took.  Returns the value of expr."
  {:added "1.0"}
  `(let [start# (. System (nanoTime))
         ret# ~expr]
     (prn (str "Elapsed time: "
               (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs"))

Use it as a base for a new macro returning number of nanoseconds spent on evaluation of a given expression.

(defmacro nsecs
  `(let [start# (. System (nanoTime))]
     (- (. System (nanoTime)) start#)))

The DefMacro solutions was not working for me, so I used this filtering solution:

(filter #(#{\0,\1,\2,\3,\4,\5,\6,\7,\8,\9,\.} %) my-double-number)

The returned value is exactly what I wanted. Thanks anyway for your suggestions and for your time. Chers

Need Your Help

How does Google's javascript API get around the cross-domain security in AJAX

google-api google-api-js-client google-ajax-api

How does Google's API make cross-domain requests back to Google, when it's on your website?

Java Best way to throw exception in a method

java exception methods throw

I have created my own type of exception and want to implement it in a method. As of now I have written it in the following way, and it works.