On Feb 24, 2013, at 9:33 AM, Marko Topolnik wrote:

> 
> Take a look at any of the Common Lisp or Haskell submissions to the Computer 
> Language Benchmarks Game web site, and you will see some programs that are 
> nowhere near what people typically write in those languages, and certainly 
> not what people would write if they weren't concerned with squeezing out the 
> last drop of performance.  Lots of mutable data structures in both, and lots 
> of type declarations in Common Lisp.
> 
> Can you really get mutability in Haskell? I thought that was impossible; 
> hence the notorious State monad.

I'm no Haskell expert, but it doesn't take much Googling to give strong 
evidence that the answer is "yes, you can get mutability in Haskell".  Search 
through this Haskell program on the Benchmarks Game site for occurrences of the 
string "unsafe".

    
http://benchmarksgame.alioth.debian.org/u64q/program.php?test=fannkuchredux&lang=ghc&id=4

Then check out the description of those operations on this web page:

    
http://hackage.haskell.org/packages/archive/array/0.3.0.2/doc/html/Data-Array-MArray.html

Similarly look for occurrences of "unsafe" in the other fastest Haskell 
programs.  I found about 4 out of 10 of them use such operations.


> Then again, even for C and Java programs on that site, people will do some 
> pretty amazing tricks they wouldn't normally do in those languages, either, 
> e.g. performing I/O in parallel with computation, even when it makes the 
> computation code more complex to give the correct answer.
> 
> Yes, I've already got frustrated with that site several times. For example, 
> Scala beats Java by a wide margin on some benchmarks. Turns out it's because 
> it uses JNI to solve the problem with the C bignum library. What relevance 
> could that have?

So ignore the results for pidigits, which is likely the one you saw that uses 
the libgmp library.  Many people who dismiss the Benchmarks Game site point 
that out, and I agree: the pidigits benchmark doesn't tell you much, other than 
whether the program uses the libgmp library or not.

Instead look at the results for other programs that don't pull those tricks, or 
ignore the site entirely.  If you worry that some people hastily draw the wrong 
conclusions from the results on that site, such people are being insufficiently 
critical in their interpretation of the data.


> For Clojure, I'd recommend doing the same thing I'd recommend in just about 
> any language: write the code that occurs to you first to get it correct.  If 
> it is fast enough for your purposes, whatever those are, you are done.  If 
> not, use a profiler to see where most of the time is spent, and then start 
> working on optimizations in the same language if they are worth your time to 
> do so.  If they get too difficult in the original language, dropping down to 
> a lower-level language (e.g. Java, C, assembler) is often a choice you can 
> make, depending upon your deployment restrictions.
> 
> The important consideration is, just how many times the idiomatic code is 
> slower? In my book it is a worthwhile goal to improve from 100x slower to 10x 
> slower, even if that outcome still means it's quite a bit slower.

In my experience writing Clojure programs for the Benchmarks Game, getting 
within 10x is fairly easy, and doesn't require much knowledge other than 
eliminating Clojure reflection, and using a decent algorithm that doesn't throw 
in an extra factor of N by accident.  It often helps to use mutable Java arrays 
and Clojure loops, too.

Getting better than 3x of a Java program that pulls out all the optimization 
tricks is tougher in Clojure.  If you're in that situation, I'd say use Java 
and simplify your life.

Andy

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to