(defn timed-foo [times n]
  (let [start (now)]
    (foo n)
    (conj times [n (- (now) start)])))

(defn format-time [[n t]]
  (format "%2d threads took %7d milliseconds" n t))

(->> numbers
     (reduce timed-foo [])
     (map format-time)
     println)



On Sat, Apr 12, 2014 at 3:15 PM, Cecil Westerhof <cldwester...@gmail.com>wrote:

> 2014-04-12 15:49 GMT+02:00 Cecil Westerhof <cldwester...@gmail.com>:
>
> 2014-04-12 15:06 GMT+02:00 Fergal Byrne <fergalbyrnedub...@gmail.com>:
>>
> or to convert your code to something more functional (and including defns
>> for now and foo):
>>
>>>
>>> (defn now [] (. System currentTimeMillis))
>>>
>>
>> I already defined it as:
>>     (defn now []
>>       (new java.util.GregorianCalendar))
>>
>> I use it for other things also.
>>
>>
>>
>>> (def numbers     '(4 6 8 10))
>>>
>>> (defn foo [n] (reverse (map #(* % %) (range (Math/pow n 5)))))
>>>
>>> (count (foo 10))
>>>
>>> (defn timed-foo [times n]
>>>   (let [start (now)]
>>>     (foo n)
>>>     (conj times (- (now) start))))
>>>
>>> (reduce timed-foo [] numbers) => [0 0 4 14]
>>>
>>
>> I am going to look into this.
>>
>
> I made it in the following:
> (defn timed-foo [times n]
>   (let [start (.getTimeInMillis (now))]
>     (foo n)
>     (conj times (format "%2d threads took %7d milliseconds"
>                         n (- (.getTimeInMillis (now)) start)))))
>
>
> (doseq [i (reduce timed-foo [] numbers)]
>        (println i))
> That looks a lot better. Thanks. (It would be better to move the format to
> the doseq I think, but at the moment, it is good enough.)
>
> --
> Cecil Westerhof
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Fergal Byrne, Brenter IT

Author, Real Machine Intelligence with Clortex and NuPIC
https://leanpub.com/realsmartmachines

<http://www.examsupport.ie>http://inbits.com - Better Living through
Thoughtful Technology
http://ie.linkedin.com/in/fergbyrne/
https://github.com/fergalbyrne

e:fergalbyrnedub...@gmail.com t:+353 83 4214179
Formerly of Adnet edi...@adnet.ie http://www.adnet.ie

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to