[Haskell-cafe] Performance: MD5

Andrew Coppin andrewcoppin at btinternet.com
Sun May 18 06:20:49 EDT 2008


Don Stewart wrote:
> andrewcoppin:
>   
>> Wait... you're telling me to give up? To not even try??
>>
>> So all that bravado about Haskell enabling higher-level optimisations to 
>> produce a result faster than C is actually complete nonesense?
>>     
>
> What optimisations were operating in your md5 implementation that you
> could expect it do match the C version?
>   

I was hoping that things would be inlined, small loops unrolled, and I'd 
end up with more or less the same imperative loops as the C version has. 
I wasn't expecting to *beat* C in this particular case, but I expected 
to get somewhere fairly near it.

> If you want to write code that matches some heavily
> optimised md5 in C then your
> Haskell will need to compile down to similar data and control structures.
>   

Agreed.

> (did you look at the C implementation?)
>   

I can't read C. (FWIW, I think I did briefly stare at the sources, but 
eventually gave up because I simply had no clue what's going on.)

> Does it?
>   

I'm still figuring out how to answe that question.

[As in, "the profiler says 60% of my time is spent inside one function, 
I've now tried writing that function 6 different ways, and currently it 
compiles to about 3 pages of Core that I'm still attempting to 
decypher". Given the size of the Core for this function, I'd say it's 
probably inlining and unrolling just fine...]

> So, as Bulat says, explain why your code should have similar performance
> to the C version.

Because it executes the same algorithm? I mean, there's essentially only 
one way round that you can perform the MD5 algorithm, so it just comes 
down to how efficiently you execute the steps involved.

> It would be much more useful than complaining about
> the community who patiently help you day in and out.
>   

Telling somebody "don't bother trying, it's impossible" doesn't strike 
me as terribly helpful. It doesn't make my code go any faster, and it 
certainly doesn't help me learn anything.

I guess my responce was a little harsh. But when you invest a lot of 
time and effort in something, and somebody off-handedly tells you you're 
wasting your time... it's quite upsetting.



More information about the Haskell-Cafe mailing list