I can't see your code due to the IT policies here, but I can make some generalizations - these are assuming your code is correct and you're not accidentally using an exponential algorithm (which I wouldn't preclude, 4 minutes does sound truly excessively slow, even for vectors).
Vectors are significantly slower than Java arrays due to their copy-on- write semantics. You have a few options, both of which are considered perfectly acceptable Clojure for high-performance numerical code: 1. Use transients (http://clojure.org/transients) when you update your vectors. This should give you a pretty significant speed increase. 2. Alternatively, use native java arrays. Clojure provides a complete set of functions for creating and mutating raw Java arrays 3. Use type hints to eliminate reflection at choke points in your processing. If you do 2 and 3, you should get pretty close to native Java speeds. On May 28, 12:20 pm, Rubén Béjar <ruben.be...@gmail.com> wrote: > Hi again, > I have tried a few more things: > I have done the same in Java but using an array > of Integers, instead of an array of ints. It just takes > 78 ms. (more than 16, still far less than 4 secs). > I have also tried with an update function which just returns a > fixed 1. It still takes some 400 ms. to update de > data vector of the CA. This is similar to the time > it is giving me to create a vector of 1's with this function: > (time (vec (repeat 250000 1))). > I was not expecting Clojure vectors so much slower than > Java arrays. Is that comparison so "unfair"? Next thing > I am trying is using Java Vectors in my Java > implementation... > Rubén > Rubén Béjar escribió:Hi all, > I am new to the list and to Clojure. I have been working in > implementing some 2D cellular automata (CA) just to have a project > to teach Clojure to myself. After some work I have something that > works, but it is pretty slow. The function that takes a CA > of 500x500 cells (integers) and returns an updated (*) copy > takes 4 s. (using Clojure vectors), while doing more or less the same in Java > (using arrays and primitive types) takes more or > less 16 *ms.*. I expected some difference, but not that big. Before > trying to use Java arrays and primitive types > in Clojure, I would like to know how my Clojure approach can > be improved (I am willing to sacrifice some performance to keep > it "more Clojure", but not that much). > As I do not want to post a bunch of horrible code full of comments > and not properly indented, I have extracted what i hope are the > main pieces, written some comments and posted it here:http://snipt.org/Okpk > Pasting that code in a new file in Eclipse (I am using > counterclockwise) and running it in the REPL prints this: > Clojure 1.1.0-alpha-SNAPSHOT > "Elapsed time: 4355.363706 msecs" > "Elapsed time: 4416.98562 msecs" > 1:1 user=> #<Namespace cellular-automata-basic> > 1:2 cellular-automata-basic=> > I would thank a lot any hint, suggestion, comment, or > whatever... :-) > Best regards, > Rubén > (*) The update consists on adding the values of the 8 neighbours > of every cell and changing it if that sum is between two fixed > numbers.-- Rubén BÉJAR HERNÁNDEZ Dpto. de Informática e Ingeniería de > Sistemas - Universidad de Zaragoza (Computing and Systems Engineering > Department - Universidad de Zaragoza) c/ María de Luna 1, 50018 Zaragoza, > Spain Tel: (+34) 976 76 2332 (Fax: 1914) e-mail:rbe...@unizar.esgrupo IA3 > (IA3 Laboratory) -http://iaaa.cps.unizar.es On May 28, 12:20 pm, Rubén Béjar <ruben.be...@gmail.com> wrote: > Hi again, > I have tried a few more things: > I have done the same in Java but using an array > of Integers, instead of an array of ints. It just takes > 78 ms. (more than 16, still far less than 4 secs). > I have also tried with an update function which just returns a > fixed 1. It still takes some 400 ms. to update de > data vector of the CA. This is similar to the time > it is giving me to create a vector of 1's with this function: > (time (vec (repeat 250000 1))). > I was not expecting Clojure vectors so much slower than > Java arrays. Is that comparison so "unfair"? Next thing > I am trying is using Java Vectors in my Java > implementation... > Rubén > Rubén Béjar escribió:Hi all, > I am new to the list and to Clojure. I have been working in > implementing some 2D cellular automata (CA) just to have a project > to teach Clojure to myself. After some work I have something that > works, but it is pretty slow. The function that takes a CA > of 500x500 cells (integers) and returns an updated (*) copy > takes 4 s. (using Clojure vectors), while doing more or less the same in Java > (using arrays and primitive types) takes more or > less 16 *ms.*. I expected some difference, but not that big. Before > trying to use Java arrays and primitive types > in Clojure, I would like to know how my Clojure approach can > be improved (I am willing to sacrifice some performance to keep > it "more Clojure", but not that much). > As I do not want to post a bunch of horrible code full of comments > and not properly indented, I have extracted what i hope are the > main pieces, written some comments and posted it here:http://snipt.org/Okpk > Pasting that code in a new file in Eclipse (I am using > counterclockwise) and running it in the REPL prints this: > Clojure 1.1.0-alpha-SNAPSHOT > "Elapsed time: 4355.363706 msecs" > "Elapsed time: 4416.98562 msecs" > 1:1 user=> #<Namespace cellular-automata-basic> > 1:2 cellular-automata-basic=> > I would thank a lot any hint, suggestion, comment, or > whatever... :-) > Best regards, > Rubén > (*) The update consists on adding the values of the 8 neighbours > of every cell and changing it if that sum is between two fixed > numbers.-- Rubén BÉJAR HERNÁNDEZ Dpto. de Informática e Ingeniería de > Sistemas - Universidad de Zaragoza (Computing and Systems Engineering > Department - Universidad de Zaragoza) c/ María de Luna 1, 50018 Zaragoza, > Spain Tel: (+34) 976 76 2332 (Fax: 1914) e-mail:rbe...@unizar.esgrupo IA3 > (IA3 Laboratory) -http://iaaa.cps.unizar.es -- 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