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
And this code:
(set! *warn-on-reflection* true)
(import 'java.awt.geom.Point2D$Float)
(dotimes [_ 5]
(let [q (Point2D$Float. 1 2)]
(time (dotimes [_ (int 1e9)]
(.getX q)))))
prints this:
"Elapsed time: 2220.368412 msecs"
"Elapsed time: 2214.941962 msecs"
"Elapsed time: 2168.259558 msecs"
"Elapsed time: 2162.655501 msecs"
"Elapsed time: 2172.560098 msecs"
On Mar 11, 7:05 am, Chouser <[email protected]> wrote:
> On Thu, Mar 10, 2011 at 11:26 PM, Jarl Haggerty <[email protected]>
> wrote:
> > Hmm, I should have thought of that.
>
> > NewClojure:
>
> > (ns hello.test
> > (import org.jbox2d.common.Vec2)
> > (:gen-class))
>
> > (defn -main [& args]
> > (dotimes [q 5]
> > (let [#^Vec2 a (Vec2. 1 2)
> > #^Vec2 b (Vec2. 3 4)]
> > (time (loop [x (int 0)]
> > (when (< x (int 1e9))
> > (.addLocal a b)
> > (recur (unchecked-inc x))))))))
>
> I think if you turn on reflection warnings and remove those type
> hints, you'll find those hints aren't useful. In which case I'd
> recommend leaving them out.
>
> --Chouser
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en