On Thu, Sep 20, 2012 at 11:57 PM, Bas van Dijk <span dir="ltr"><<a href="mailto:v.dijk.bas@gmail.com" target="_blank">v.dijk.bas@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 20 September 2012 22:55, Gregory Collins <<a href="mailto:greg@gregorycollins.net">greg@gregorycollins.net</a>> wrote:<br>
> consequently, there seems to be no reason to use the word8 library: not only<br>
> is it not faster, it's actually a pessimization.<br>
<br>
</div>When I run the following benchmark:<br>
<div class="im"><br>
main :: IO ()<br>
main = do<br>
input <- S.readFile "bench.hs"<br>
defaultMain<br>
</div> [ bench "Word8-local" $ nf (S.length . S.map toLower8) input<br>
, bench "Char8 toLowerC" $ nf (S.length . S8.map toLowerC) input<br>
]<br>
<br>
toLower8 :: Word8 -> Word8<br>
toLower8 w<br>
| isUpper8 w = w + 32<br>
| otherwise = w<br>
{-# INLINE toLower8 #-}<br>
<br>
isUpper8 :: Word8 -> Bool<br>
isUpper8 w = 0x41 <= w && w <= 0x5a<br>
|| 0xc0 <= w && w <= 0xd6<br>
|| 0xd8 <= w && w <= 0xde<br>
{-# INLINE isUpper8 #-}<br>
<br>
toLowerC :: Char -> Char<br>
toLowerC w<br>
| isUpperC w = unsafeChr $ ord w + 0x20<br>
| otherwise = w<br>
<br>
isUpperC :: Char -> Bool<br>
isUpperC w = '\x41' <= w && w <= '\x5a'<br>
|| '\xc0' <= w && w <= '\xd6'<br>
|| '\xd8' <= w && w <= '\xde'<br>
<br>
I get the following results:<br>
<br>
benchmarking Word8-local<br>
mean: 8.939985 us, lb 8.921876 us, ub 8.960350 us, ci 0.950<br>
std dev: 97.99953 ns, lb 86.79926 ns, ub 113.6396 ns, ci 0.950<br>
<br>
benchmarking Char8 toLowerC<br>
mean: 3.468023 us, lb 3.461577 us, ub 3.475718 us, ci 0.950<br>
std dev: 35.93801 ns, lb 30.56892 ns, ub 49.77021 ns, ci 0.950<br>
<br>
However when I _remove_ the INLINE pragmas they become equally fast:<br></blockquote><div><br></div><div>That's what I originally expected the results to be. The fact that removing those INLINE pragmas makes things better is........strange. I'm going to forward this thread to Simon to see what he thinks about it.</div>
</div><div><br></div><div>G</div>-- <br>Gregory Collins <<a href="mailto:greg@gregorycollins.net" target="_blank">greg@gregorycollins.net</a>><br>