Ok, I changed the java version to add x to an accumulator and now it
runs just a little slower than clojure, probably because of the extra
adding.  And if you don't mind one more trivial example...

Should I be able assign to the members of an object in Clojure just as
fast as I could in Java?  I have two forms below, one calls the
setLocation of a Point2D object, and the other does the assignment in
Clojure and is about 3 times slower.

(dotimes [_ 5]
  (let [a (Point2D$Double. 1 2)
        b (Point2D$Double. 2 3)
        add (fn [^Point2D a ^Point2D b]
              (.setLocation a
                            (+ (.getX a) (.getX b))
                            (+ (.getY a) (.getY b))))]
    (time (dotimes [_ (int 1e9)]
            (add a b)))))
(dotimes [_ 5]
  (let [a (Point2D$Double. 1 2)
        b (Point2D$Double. 2 3)
        add (fn [^Point2D$Double a ^Point2D$Double b]
              (set! (.x a) (+ (.x a) (.x b)))
              (set! (.y a) (+ (.y a) (.y b))))]
    (time (dotimes [_ (int 1e9)]
            (add a b)))))

On Mar 18, 10:08 pm, David Nolen <dnolen.li...@gmail.com> wrote:
> On Sat, Mar 19, 2011 at 12:26 AM, Jarl Haggerty <jarlhagge...@gmail.com>wrote:
>
>
>
> > Is there a reason I can't get this clojure program to compare with the
> > java one?
>
> > The following code:
>
> > for(int q = 0;q < 5;q++){
> >     Point2D.Float a = new Point2D.Float(1, 2), b = new
> > Point2D.Float(3, 4);
> >    long start = System.currentTimeMillis();
> >    for(int d = 0;d < (int)1e9;d++){
> >        a.getX();
> >    }
> >    long stop = System.currentTimeMillis();
> >    System.out.println(stop - start);
> > }
>
> > prints this:
>
> > 7
> > 6
> > 0
> > 0
> > 0
>
> That's 1 billion operations getting JITed away. Not really useful for
> profiling real programs, eh? :)
>
> David

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

Reply via email to