> Lesson learned here for me is that only use java array when absolutely 
> necessary. I always thought since it's primitive array, it should be the 
> fastest. Apparently not!
This bears repeating. I often find it hit-and-miss to know when idiomatic 
Clojure will be faster than turning to Java. Are there any resources (blogs, 
books etc) to help increase intuition as to where to go? Other than time, the 
REPL and criterium of course :)

> On 11 Jun 2015, at 10:26, Ritchie Cai <ritchie...@gmail.com> wrote:
> 
> Yup. As it turns out, the slow down is pretty much due to reflection. After 
> added type hint, it's much better now.
> The code can be viewed here: 
> https://github.com/malloc82/imaging/blob/45475b99f564b1ac77e668e04b91cb9c01a096d7/src/imaging/dicom.clj#L46-L161
> 
> They are three different implementations, here is the performance for each 
> one:
> imaging.dicom> (def data1 (timer "total: " (load-txt-image 
> "resources/PCT/CTP404_merged/x_11.txt")))
>   ==> timing:      loading txt data 513.267672 ms
>   ==> timing:                   max 61.782047 ms
>   ==> timing:                   min 62.4488 ms
>   ==> timing:   update pixel values 281.222481 ms
>   ==> timing:               total:  952.981063 ms
> #'imaging.dicom/data1
> imaging.dicom> (def data3 (timer "total: " (load-txt-image_matrix 
> "resources/PCT/CTP404_merged/x_11.txt")))
>   ==> timing:      loading txt data 728.267621 ms
>   ==> timing:                   max 25.00652 ms
>   ==> timing:                   min 25.575979 ms
>   ==> timing:   update pixel values 111.647122 ms
>   ==> timing:               total:  926.00495 ms
> #'imaging.dicom/data3
> imaging.dicom> (def data2 (timer "total: " (load-txt-image_array 
> "resources/PCT/CTP404_merged/x_11.txt")))
>   ==> timing:      loading txt data 664.818514 ms
>   ==> timing:            min max :  429.855274 ms
>   ==> timing:   update pixel values 361.323422 ms
>   ==> timing:               total:  1491.792197 ms
> #'imaging.dicom/data2
> imaging.dicom> 
> 
> The core.matrix one is the fastest, persistent vector is the second, but very 
> close. Double array is actually the slowest one.
> Lesson learned here for me is that only use java array when absolutely 
> necessary. I always thought since it's primitive array, it should be the 
> fastest. Apparently not!
> 
> Thanks for the hint.
> 
> On Wednesday, June 10, 2015 at 3:08:44 PM UTC-5, Andy Fingerhut wrote:
> Add this line at the top of your file where you try areduce and loop, and 
> look for any reflection warnings that occur when loading the file:
> 
> (set! *warn-on-reflection* true)
> 
> If there are none, probably best to post a link to your code, or paste it in 
> a message here if it is short enough, so others can give more precise 
> suggestions.
> 
> Andy
> 
> On Wed, Jun 10, 2015 at 1:03 PM, Ritchie Cai <ritch...@gmail.com 
> <javascript:>> wrote:
> I'm working on a java array of double with 1280000 elements. I need the max 
> and min values of the array. So I initially tried areduce and loop, both 
> gives runs around 20 seconds. But when try (apply max (vec array)) I get 
> result under 90 ms.
> Can anyone explain why there is such a big difference?
> Also if want to iterate large java array like this to do some other 
> operations, e.g. convolution, what's the best way to go? Is there another 
> fast way to iterate through array or do I need to convert array into vector?
> 
> Thanks
> Ritchie
> 
> 
> -- 
> 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 <javascript:>
> 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 <javascript:>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en 
> <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+u...@googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> 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 
> <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 
> <mailto:clojure+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
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