On Jul 1, 10:24 pm, fft1976 <fft1...@gmail.com> wrote:
>
> > > Has either one of you tried adding type declarations?
>
> > Yes, I had them from the start.
>
> Isn't it strange that Clojure with type declarations (that some people
> say should be as fast as Java) was only as fast as Python (which does
> not allow type declarations and does not exactly have a reputation for
> speed)?

I don't think type declarations help much in this case. For instance,
I have run java with -Xrunhprof option, with my "functional"
implementation the top list looks like this:

CPU SAMPLES BEGIN (total = 2241) Wed Jul  1 22:57:01 2009
rank   self  accum   count trace method
   1 20.30% 20.30%     455 301116 clojure.lang.RT.next
   2 14.73% 35.03%     330 301122 clojure.lang.RT.first
   3  9.37% 44.40%     210 301121 clojure.lang.Var.deref
   4  5.85% 50.25%     131 301134 clojure.lang.Var.deref
   5  4.73% 54.98%     106 301123 clojure.lang.Var.deref
   6  3.53% 58.50%      79 301138 clojure.core
$reduce__267$fn__270.invoke

etc...

And when I run my latest code:

CPU SAMPLES BEGIN (total = 4257) Wed Jul  1 23:05:17 2009
rank   self  accum   count trace method
   1  0.42%  0.42%      18 301156 java.lang.reflect.Array.getDouble
   2  0.38%  0.80%      16 301192 java.lang.reflect.Array.getDouble
   3  0.38%  1.17%      16 301238 java.lang.reflect.Array.getDouble
   4  0.35%  1.53%      15 301209 java.lang.reflect.Array.getDouble
   5  0.35%  1.88%      15 301235 java.lang.reflect.Array.getDouble
   6  0.33%  2.21%      14 301247 java.lang.reflect.Array.getDouble
   7  0.33%  2.54%      14 301702 java.lang.reflect.Array.getDouble
   8  0.33%  2.87%      14 301164 java.lang.reflect.Array.getDouble
   9  0.33%  3.19%      14 301337 java.lang.reflect.Array.getDouble
 10  0.31%  3.50%      13 301291 java.lang.reflect.Array.getDouble

(with around 400 more lines like this)

Please note the "self" column on both logs. So, my first approach was
maybe intuitive to me but it was dealing with a lot of hash lookups,
shuffling with vectors, merging hashes and whatnot. Performance was
not my goal, I just wanted to make the VM run correctly. Also, as an
exercise I wanted to use immutable/persistent data structures, to see
how I could implement such a thing as a virtual machine in a
functional language. I became interested in performance when I
discovered that my VM runs at 45 iterations/second. That had to be
improved, so I tweaked it until I got 500 (still using immutable data
structures), and that allowed me to continue with the contest.

Now, thanks to Nicolas's suggestions I get just short of 5000
iterations/s (yes, I improved it a bit more since my last post), of
course, with the help of mutable java arrays. That is nice.

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