[Haskell-cafe] Performance help

2007-11-13 Thread Justin Bailey
I've been working on a program over the last few days to evolve cellular automata rules using a genetic algorithm. Luckily, this email has nothing to do with CAs but everything to do with Haskell performance. For those who don't know, a CA is represented as a row of cells, where each can be

Re: [Haskell-cafe] Performance help

2007-11-13 Thread Ryan Ingram
One observation is that you're doing a lot of redundant Bool - Int conversion. As you iterate across the array in fillArray, the rule you are using for the next cell is almost entirely determined by the rule you are using for the current cell; lop off the top bit, shift left by one, and add the

Re: [Haskell-cafe] Performance help

2007-11-13 Thread Ryan Ingram
On 11/13/07, Ryan Ingram [EMAIL PROTECTED] wrote: Also, what stops getRule from going off the end of the array? I didn't see anything that prevented that in the code, and you're using unsafeAt, which seems like a potential bug. Never mind, I realized this is a ring buffer with `mod` s.

Re: [Haskell-cafe] Performance help

2007-11-13 Thread Justin Bailey
On Nov 13, 2007 2:21 PM, Ryan Ingram [EMAIL PROTECTED] wrote: Never mind, I realized this is a ring buffer with `mod` s. That's another slow operation when you're doing code as tight as this. If you can guarantee the ring is a power of 2 in size you can use a mask instead, or use my

Re: [Haskell-cafe] Performance help

2007-11-13 Thread Stefan O'Rear
On Tue, Nov 13, 2007 at 02:45:33PM -0800, Justin Bailey wrote: On Nov 13, 2007 2:21 PM, Ryan Ingram [EMAIL PROTECTED] wrote: Never mind, I realized this is a ring buffer with `mod` s. That's another slow operation when you're doing code as tight as this. If you can guarantee the ring is

Re: [Haskell-cafe] Performance help

2007-11-13 Thread Ryan Ingram
Sure, if the ring size is a power of two, and a is greater than or equal to 0, then a `mod` ringSize == a .. (ringSize - 1) that is: a `mod` 8 == a .. 7 a `mod` 256 == a .. 255 etc. On 11/13/07, Justin Bailey [EMAIL PROTECTED] wrote: On Nov 13, 2007 2:21 PM, Ryan Ingram [EMAIL PROTECTED]

Re: [Haskell-cafe] Performance help

2007-11-13 Thread Justin Bailey
On Nov 13, 2007 2:49 PM, Stefan O'Rear [EMAIL PROTECTED] wrote: About how wide are your rules usually? 7 bits (3 neighbors on each side plus the current cell). Justin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Performance help

2007-11-13 Thread Justin Bailey
I implement bit shifting to get the next rule, as you suggested, and that cut my run time by 75%. It went from 200 seconds to do 100 rules on 100 CAs to 50 seconds. Amazing. Justin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Performance help

2007-11-13 Thread Derek Elkins
On Tue, 2007-11-13 at 14:21 -0800, Ryan Ingram wrote: On 11/13/07, Ryan Ingram [EMAIL PROTECTED] wrote: Also, what stops getRule from going off the end of the array? I didn't see anything that prevented that in the code, and you're using unsafeAt, which seems like a

Re: [Haskell-cafe] Performance Help

2007-03-24 Thread Dominic Steinitz
On Friday 16 March 2007 21:24, Ian Lynagh wrote: On Sun, Mar 11, 2007 at 08:18:44PM +, Dominic Steinitz wrote: I have re-written the sha1 code so that it is (hopefully) easy to see that it faithfully implements the algorithm (see http://www.itl.nist.gov/fipspubs/fip180-1.htm). Having

Re: [Haskell-cafe] Performance Help

2007-03-24 Thread Ian Lynagh
On Sat, Mar 24, 2007 at 01:46:33PM +, Dominic Steinitz wrote: Thanks. I'm trying to build just SHA1 but I am getting the following linker errors. Do you know what option I should be adding? [EMAIL PROTECTED]:~/sha11 ghc -o perfTest perfTest.hs -iIgloo/darcs-unstable/src --make -lz

Re: [Haskell-cafe] Performance Help

2007-03-19 Thread Dominic Steinitz
On Friday 16 March 2007 21:29, David Brown wrote: Ian Lynagh wrote: On Sun, Mar 11, 2007 at 08:18:44PM +, Dominic Steinitz wrote: I have re-written the sha1 code so that it is (hopefully) easy to see that it faithfully implements the algorithm (see

Re: [Haskell-cafe] Performance Help

2007-03-16 Thread Ian Lynagh
On Sun, Mar 11, 2007 at 08:18:44PM +, Dominic Steinitz wrote: I have re-written the sha1 code so that it is (hopefully) easy to see that it faithfully implements the algorithm (see http://www.itl.nist.gov/fipspubs/fip180-1.htm). Having got rid of the space leak, I have been trying to

Re: [Haskell-cafe] Performance Help

2007-03-16 Thread David Brown
Ian Lynagh wrote: On Sun, Mar 11, 2007 at 08:18:44PM +, Dominic Steinitz wrote: I have re-written the sha1 code so that it is (hopefully) easy to see that it faithfully implements the algorithm (see http://www.itl.nist.gov/fipspubs/fip180-1.htm). Having got rid of the space leak, I have

Re: [Haskell-cafe] Performance Help

2007-03-12 Thread Neil Mitchell
Hi I notice that there's not much user-accessible documentation of what you can expect GHC (or some other Haskell implementation) to do and not do with a given piece of code. Yhc/nhc/Hugs - nothing GHC - inlining, simplification, fusion if you use the build in functions in a specified way,

[Haskell-cafe] Performance Help

2007-03-11 Thread Dominic Steinitz
I have re-written the sha1 code so that it is (hopefully) easy to see that it faithfully implements the algorithm (see http://www.itl.nist.gov/fipspubs/fip180-1.htm). Having got rid of the space leak, I have been trying to improve performance. Currently, the haskell code is 2 orders of

Re: [Haskell-cafe] Performance Help

2007-03-11 Thread Stefan O'Rear
On Sun, Mar 11, 2007 at 08:18:44PM +, Dominic Steinitz wrote: Word128 ai bi ci di ei = ss 128 is not divisible by 5. You should probably rename that type :) Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Performance Help

2007-03-11 Thread Dominic Steinitz
On Sunday 11 March 2007 20:46, Stefan O'Rear wrote: On Sun, Mar 11, 2007 at 08:18:44PM +, Dominic Steinitz wrote: Word128 ai bi ci di ei = ss 128 is not divisible by 5. You should probably rename that type :) Stefan I must have been thinking of MD5. Yes Word160 would be better.

Re: [Haskell-cafe] Performance Help

2007-03-11 Thread Bryan O'Sullivan
Dominic Steinitz wrote: Any help would be appreciated. I notice that there's not much user-accessible documentation of what you can expect GHC (or some other Haskell implementation) to do and not do with a given piece of code. For example, you have a lot of little definitions that clearly