#1687: A faster (^)-function.
------------------------------------------+---------------------------------
Reporter: [EMAIL PROTECTED] | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.6.1
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Os: Unknown | Testcase:
Architecture: Unknown |
------------------------------------------+---------------------------------
Comment (by moonlite):
ghc --make -O2 is the flags i use.
I tested with this:
{{{
import Prelude hiding ((^))
import TestData
main = print $ (2 ^ e) `mod` 2
{-# SPECIALISE (^) ::
Integer -> Integer -> Integer,
Integer -> Int -> Integer,
Int -> Int -> Int #-}
(^):: (Num a, Integral b) => a -> b -> a
_ ^ 0= 1
x ^ n | n > 0 = f x (n-1) x
where f _ 0 y = y
f a d y = g a d
where
g b i | even i = g (b*b) (i `quot` 2)
| otherwise = f b (i-1) (b*y)
_ ^ _= error "Prelude.^: negative exponent"
}}}
And got these results:
{{{
[EMAIL PROTECTED] ~/code/haskell/pow $ time ./ghctest
0
real 0m11.713s
user 0m11.473s
sys 0m0.136s
[EMAIL PROTECTED] ~/code/haskell/pow $ time ./ghctest
0
real 0m12.233s
user 0m11.529s
sys 0m0.136s
[EMAIL PROTECTED] ~/code/haskell/pow $ time ./ghctest
0
real 0m11.585s
user 0m11.453s
sys 0m0.104s
[EMAIL PROTECTED] ~/code/haskell/pow $ time ./ghctest
0
real 0m11.632s
user 0m11.469s
sys 0m0.112s
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1687>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs