[Haskell-beginners] Help with slow algorithm
Daniel Fischer
daniel.is.fischer at web.de
Fri May 14 22:16:49 EDT 2010
On Saturday 15 May 2010 04:00:06, Diego Echeverri wrote:
> Hi Daniel. Thanks for your answer.
>
> > One point: Packing a long list is bad. That takes a lot of memory and
> > is slow, if you create a list, it's going to be faster to use normal
> > String-IO to output it.
>
> The thing is that later I do some operations with it (solve). just by
> changing to ByteString everything got faster.
>
You should think a little about avoiding that.
> > Another point: biggerOrEquals is also too slow. Using the Ord instance
> > for ByteStrings will be faster. But I think splitting the ByteStrings
> > isn't the best way.
>
> The Ord instance of ByteStrings is lexicographic. This way:
>
> B.pack "1111" > B.pack "112" ==> False
>
> Although given the fact that both strings would be the same length,
> the Ord instance may work just fine.
>
Quite. You only test ByteStrings of equal length, so the Ord instance works
fine.
> > Third point: Use STUArrays and not STArrays if possible (much faster).
>
> Not sure if those are available in the Online Judge. I'll try it.
They're also provided by Data.Array.ST, so they are available.
>
> Thanks Again!
>
>
More information about the Beginners
mailing list