🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #1128

my haskell program is 60 times slower than java; how to speed up?

#1128
From: tromp
Date: Sat, 12 Mar 2005 19:48
40 lines
2417 bytes
I recently ported my Fhourstones integer benchmark, previously
available
in both C and Java, to Haskell.

This allowed for significantly clearer and more concise code,
with much improved modularity.

Unfortunately, performance went down the drain:( On my desktop PC, the
java version
examines over 1700K positions per second, while Haskell strains to get
25 Kpos/sec.

Source of all versions may be found on
http://www.cwi.nl/~tromp/c4/fhour.html

Curiously, profiling shows all 3 versions spend between 1/5 and 1/3
of their time on the following function for testing 4 in a row in 64bit
bitboards:

  isWon :: Word64 -> Bool
  isWon bb = dir 1 /= 0 || dir height /= 0 ||
             dir height' /= 0 || dir height'' /= 0 where
    dir d = let t = bb .&. (bb `shiftR` d) in t .&. (t `shiftR` (2*d))

So this simple strict function alone appears to be dozens times slower
in Haskell.

I think I've already added strictness annotations in all the relevant
places.

Is there any hope of getting say, within a factor of 4 of java
performance,
without sacrificing (too much of) the clarity of the source code?

regards,
-John

PS: the haskell version has slightly different move ordering and so
doesn't reproduce the test results of the other versions exactly,
but this shouldn't affect the speed as measured in pos/sec.
Technical Details
Message-ID: <1110656910.982788.232310@f14g2000cwb.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 107f24,d35b4ba0634798d,start
X-Google-Thread: 10707f,d35b4ba0634798d,start
X-Google-Attributes: gid107f24,gid10707f,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail
From: "tromp" <john.tromp@gmail.com>
Newsgroups: comp.lang.functional,fa.haskell
Subject: my haskell program is 60 times slower than java; how to speed up?
Date: 12 Mar 2005 11:48:31 -0800
Organization: http://groups.google.com
Lines: 41
Message-ID: <1110656910.982788.232310@f14g2000cwb.googlegroups.com>
NNTP-Posting-Host: 192.16.196.178
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1110656914 16126 127.0.0.1 (12 Mar 2005 19:48:34 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 12 Mar 2005 19:48:34 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: f14g2000cwb.googlegroups.com; posting-host=192.16.196.178;
   posting-account=qCwDwgwAAABh7XSYRT1uyOvBJcVtIWv_