Re: speed question

2009-04-03 Thread Raffael Cavallaro
this one is nice too: (defn draw-line [#^Graphics g y] (let [dy (- 1.25 (* y height-factor))] (doseq [x (range 0 width)] (let [dx (- (* x width-factor) 2.0)] (let [value (check-bounds dx dy) scaled (Math/round (* value color-scale)) xsca

Re: speed question

2009-04-03 Thread rzeze...@gmail.com
Could Clojure have something similar to CL's 'defconstant'? http://gigamonkeys.com/book/variables.html On Apr 2, 4:09 pm, Bradbev wrote: > It seems to me that the real solution is that the Clojure compiler > needs to support global constants.  You could probably emulate the > behaviour by rebin

Re: speed question

2009-04-02 Thread Dmitri
yeah I definitely agree that it would be nice if constants could be used without the parens. On Apr 2, 11:48 am, Paul Stadig wrote: > Yeah that works the same as defining a function, just more explicit. I was > looking for a way to define a constant and just use it as "my-const" without > having

Re: speed question

2009-04-02 Thread Dmitri
nifty :) On Apr 2, 5:10 pm, Raffael Cavallaro wrote: > If you change the color constructor you can get some nice color > effects: > > (. setColor (let [scaled (Math/round (* value color-scale))] >                      (Color.   255 (- 255 scaled) scaled))) > > will give you yellow and magenta fo

Re: speed question

2009-04-02 Thread Raffael Cavallaro
If you change the color constructor you can get some nice color effects: (. setColor (let [scaled (Math/round (* value color-scale))] (Color. 255 (- 255 scaled) scaled))) will give you yellow and magenta for example --~--~-~--~~~---~--~~ You

Re: speed question

2009-04-02 Thread Bradbev
It seems to me that the real solution is that the Clojure compiler needs to support global constants. You could probably emulate the behaviour by rebinding global vars inside the let though. (def *foo* 100) (defn bar [] (let [foo *foo*] ...)) Brad On Apr 2, 7:57 am, Paul Stadig wrote: > I

Re: speed question

2009-04-02 Thread Paul Stadig
Yeah that works the same as defining a function, just more explicit. I was looking for a way to define a constant and just use it as "my-const" without having to use the parens to call a function or a macro. I guess that would be something like a symbol macro in CL? Paul On Thu, Apr 2, 2009 at 1

Re: speed question

2009-04-02 Thread MikeM
There is definline which seems appropriate in place of the constant macros. (definline my-const [] 1) (my-const) ;= 1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send ema

Re: speed question

2009-04-02 Thread Paul Stadig
I think you are right, Brad. However, I wonder though if there is a better way to define a constant. Neither the macro nor function seems clean. I like David's wrapping-the-whole-thing-in-a-let, but what if you wanted to access the value of "width" in a different file? Would one have to resort to

Re: speed question

2009-04-02 Thread Bradbev
It would seem that macros in this case should not be required. A normal function that simply returns a constant should get inlined by the JIT. Cheers, Brad On Apr 2, 5:20 am, Dmitri wrote: > Thanks a lot, that's really helpful. I never thought of using a macro > to define constants > like that

Re: speed question

2009-04-02 Thread Dmitri
Thanks a lot, that's really helpful. I never thought of using a macro to define constants like that, it's definitely a good trick and it does seem to result in the biggest performance gain. On Apr 2, 7:25 am, Paul Stadig wrote: > I got it down to about 3 seconds. I did what William said, but the

Re: speed question

2009-04-02 Thread David Sletten
On Apr 2, 2009, at 2:05 AM, MikeM wrote: > > Starting with your version, I got about a 2x improvement with the > following: > > (defn check-bounds [x y] >(let [f2 (float 2.0) > f4 (float 4.0)] >(loop [px (float x) > py (float y) > zx (float 0.0) > z

Re: speed question

2009-04-02 Thread Dmitri
like Paul said earlier changing the globals to macros makes seems to make a huge impact. and the check-bounds and draw-line get called for each line on the screen so it makes sense that optimizations there will make a big impact. On Apr 2, 8:05 am, MikeM wrote: > Starting with your version, I go

Re: speed question

2009-04-02 Thread MikeM
Starting with your version, I got about a 2x improvement with the following: (defn check-bounds [x y] (let [f2 (float 2.0) f4 (float 4.0)] (loop [px (float x) py (float y) zx (float 0.0) zy (float 0.0) zx2 (float 0.0) zy2 (float 0.0

Re: speed question

2009-04-02 Thread Dmitri
thanks a lot, that's really helpful. On Apr 2, 7:25 am, Paul Stadig wrote: > I got it down to about 3 seconds. I did what William said, but the biggest > improvement was from changing the way *width*, *height*, and *max-steps* > were defined. I noticed that in the Java version they are constants

Re: speed question

2009-04-02 Thread Paul Stadig
I got it down to about 3 seconds. I did what William said, but the biggest improvement was from changing the way *width*, *height*, and *max-steps* were defined. I noticed that in the Java version they are constants, but in the Clojure version they are Vars which means that inside your tight inner

Re: speed question

2009-04-01 Thread William D. Lipe
I did this: (defn draw [#^Canvas canvas] (let [#^BufferStrategy buffer (. canvas getBufferStrategy) #^Graphics g (. buffer getDrawGraphics)] (doseq [y (range 0 *height*)] (let [dy (- 1.5 (* 2.5 (/ y *height*)))] (doseq [x (range 0 *width*)] (let [dx (-

Re: speed question

2009-04-01 Thread Dmitri
I'm running it as a script with: java -server -cp clojure.jar clojure.lang.Script mandelbrot.clj as I mentioned earlier, I did try forcing all the primitives, but didn't notice much of a difference, I also did try running the draw function repeatedly to make sure it wasn't just the startup times

Re: speed question

2009-04-01 Thread Dmitri
I'm running it as a script with: java -server -cp clojure.jar clojure.lang.Script mandelbrot.clj as I mentioned earlier, I did try forcing all the primitives, but didn't notice much of a difference, I did try running the draw method repeatedly to make sure it wasn't just the startup times causin

Re: speed question

2009-04-01 Thread Stuart Sierra
On Apr 1, 9:40 pm, Dmitri wrote: > I've been playing around with rendering a mandelbrot set, and using > pure java it renders about 2 seconds on my machine, however it runs > about 10 times as slow in clojure, I was curious if I'm doing anything > obviously wrong, or if it's just life :) I do run

Re: speed question

2009-04-01 Thread Dmitri
I actually tried forcing the type hints and didn't really see a noticeable improvement, just made the code hard to read for the most part. On Apr 1, 9:57 pm, CuppoJava wrote: > From a quick glance, I think the lack of type hints is what's slowing > down your Clojure code. > You can set the globa

Re: speed question

2009-04-01 Thread CuppoJava
>From a quick glance, I think the lack of type hints is what's slowing down your Clojure code. You can set the global variable *warn-on-reflection* to true, to get a sense of where to add your type hints. -Patrick --~--~-~--~~~---~--~~ You received this message be

speed question

2009-04-01 Thread Dmitri
I've been playing around with rendering a mandelbrot set, and using pure java it renders about 2 seconds on my machine, however it runs about 10 times as slow in clojure, I was curious if I'm doing anything obviously wrong, or if it's just life :) I do run it with the -server flag, which does impr