I thought I'd follow up my own question with some programs that I
should have already known about for memory profiling, which were
already installed on my Mac as part of the standard Java installation
from Apple (who are just passing them on from Sun, I'm sure), but I
didn't know about them:
jconsole -- Good for seeing how fast a java process is allocating
memory, and garbage collecting.
jmap -- Good for a quick summary of the above, or with the "-histo"
option, a much more detailed list of what kinds of objects are taking
up the most memory.
I also learned that Clojure's cons and lazy cons structures take up 48
bytes per element (at least on a Mac with 'java -client' and java
1.6.0_<foo>), which gets significant when your program has sequences
of several millions of elements about.
I've updated my github repo with a pretty decent version of the
reverse-complement benchmark in Clojure. It isn't as sequence-y as it
could be, but the more sequence-y version generates and collects
garbage so fast that it really slows things down significantly. Same
lesson from other flavors of Lisp, I guess -- you can write the
straightforward easy-to-write-and-test-and-understand code that conses
a lot (i.e. allocates memory quickly that typically becomes garbage
quite soon), or you can write the more loopy code that doesn't, but
typically starts to merge many things that you'd otherwise prefer to
separate into different functions. Just compare revcomp.clj-5.clj and
revcomp.clj-6.clj in my git repo for an example.
The nice thing is that when you don't need the "uglier" code, Clojure
and other Lisps usually let you write code much more concisely than
lower level languages. Get it working first, then optimize it. Since
I'm comparing run times of the Clojure programs versus those submitted
to the language shootout benchmark web site, some of which appear
quite contorted in order to gain performance, I wanted to do some
optimizations that you wouldn't necessarily want to do otherwise.
git://
github.com/jafingerhut/clojure-benchmarks.git
You can see my latest run time results here. I've got 4 benchmarks
written in Clojure so far, with my current versions being 6x, 8x, 12x,
and 15x more CPU time than the Java programs submitted to the language
shootout benchmark web site.
http://github.com/jafingerhut/clojure-benchmarks/blob/20d21bc169d52ca52d6a8281536838662c54e854/RESULTS
I could make some of these significantly closer in speed to the Java
versions, but I suspect that they will start looking more and more
like the Java versions if I do, except with Clojure syntax for Java
calls. I'm happy to be proved wrong on that, if someone finds better
Clojure versions than I've got.
Thanks,
Andy
On Jul 30, 11:00 am, Andy Fingerhut <
andy_finger...@alum.wustl.edu>
wrote:
>
http://github.com/jafingerhut/clojure-benchmarks/blob/4ab4f41c6f96344...