Re: Question regarding java array

2015-06-15 Thread Ritchie Cai
Aww ... with that it's around 3ms now. Thanks :) On Monday, June 15, 2015 at 7:34:36 PM UTC-5, Jason Wolfe wrote: > > Might also be something to do with this: > > https://github.com/Prismatic/hiphip#performance-know-your-options > > > > On Monday, June 15, 2015 at 3:27:59 PM UTC-7, Ritchie Cai wro

Re: Question regarding java array

2015-06-15 Thread Jason Wolfe
Might also be something to do with this: https://github.com/Prismatic/hiphip#performance-know-your-options On Monday, June 15, 2015 at 3:27:59 PM UTC-7, Ritchie Cai wrote: > > My java was 1.8.0_05-b13. Upgraded it. Now it's around 9ms, close enough. > > Thanks a lot. > > On Monday, June 15, 20

Re: Question regarding java array

2015-06-15 Thread Ritchie Cai
My java was 1.8.0_05-b13. Upgraded it. Now it's around 9ms, close enough. Thanks a lot. On Monday, June 15, 2015 at 4:59:57 PM UTC-5, Steven Yi wrote: > > I typed the array-max code and test in a REPL launched with "lein > repl" in a terminal. I did do that in the root of one of my projects >

Re: Question regarding java array

2015-06-15 Thread Steven Yi
I typed the array-max code and test in a REPL launched with "lein repl" in a terminal. I did do that in the root of one of my projects that had settings on to use 1.7.0 and to warn on reflection and unchecked math. When I launched just now I have these versions reported to the terminal: REPL-y 0.3

Re: Question regarding java array

2015-06-15 Thread Ritchie Cai
Ha, you are right. That really make things a lot faster now. All three different implementations now pretty much runs about the same speed, no one is significantly faster or slower. Really appreciate your help. However, what really puzzles me at this point is that array-max call speed. On all

Re: Question regarding java array

2015-06-11 Thread Steven Yi
I'm not sure why you'd see much slower results there. For reference, I'm on a Core i7-2720-M (MacbookPro 8,1 13" early 2011), and was using clojure-1.7-beta3. Also, I looked at the code you posted and I'm not so sure about your assumption that Java arrays are slower: * in load-txt-image_array, y

Re: Question regarding java array

2015-06-11 Thread Ritchie Cai
Unfortunately, I don't get to decide the data format. It's a dump from previous stage. Also, it's supposed to be super easy for Physics people to look at. If you every work with them, you'll know what I mean XD. But thanks for the suggestion. On Thursday, June 11, 2015 at 7:30:07 AM UTC-5, Andy

Re: Question regarding java array

2015-06-11 Thread Andy-
On Thursday, June 11, 2015 at 5:32:02 AM UTC-4, Ritchie Cai wrote: > > Just wondering though, is there a faster way to load an array than this > way? > https://github.com/malloc82/imaging/blob/45475b99f564b1ac77e668e04b91cb9c01a096d7/src/imaging/dicom.clj#L138 > the data file I'm trying to read f

Re: Question regarding java array

2015-06-11 Thread Colin Yates
> 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. Ar

Re: Question regarding java array

2015-06-11 Thread Ritchie Cai
Yup. Reflection is issue, I needed type hint. However, on another note, I notice that in your first test case, your evaluation takes about 3 ms, but on my machine it takes 76 ms. I'm running a Xeon CPU at 3.5 GHZ, clojure-1.7-RC1. What could cause such a huge different timing? Thanks. On Wedn

Re: Question regarding java array

2015-06-11 Thread Ritchie Cai
I tried with vectorz here: https://github.com/malloc82/imaging/blob/45475b99f564b1ac77e668e04b91cb9c01a096d7/src/imaging/dicom.clj#L130-L161 and I'm really impressed with it's performance. The performance is shown here: imaging.dicom> (def data3 (timer "total: " (load-txt-image_matrix "resourc

Re: Question regarding java array

2015-06-11 Thread Ritchie Cai
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 implementation

Re: Question regarding java array

2015-06-10 Thread Steven Yi
As mentioned by Colin and Andy, I would guess it would be some form of boxing and reflection going on. I tried the following: (defn array-max [^doubles arr] (let [len (alength arr)] (loop [m Double/NEGATIVE_INFINITY indx 0] (if (< indx len) (recur (max m (aget arr indx))

Re: Question regarding java array

2015-06-10 Thread Mikera
Consider using core.matrix with vectorz-clj for operations on large numerical arrays / vectors of doubles. It is a *lot* faster than using Clojure vectors for this kind of scenario, plus it has a lot of helpful array operations already defined. (use 'clojure.core.matrix) (def v (array :vectorz

Re: Question regarding java array

2015-06-10 Thread Colin Yates
Will guess in the dark but would boxing come into play here? > On 10 Jun 2015, at 21:03, Ritchie Cai wrote: > > I'm working on a java array of double with 128 elements. I need the max > and min values of the array. So I initially tried areduce and loop, both > gives runs around 20 seconds.

Re: Question regarding java array

2015-06-10 Thread Andy Fingerhut
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 other

Question regarding java array

2015-06-10 Thread Ritchie Cai
I'm working on a java array of double with 128 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?