Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell SMP is superior

Name: Anonymous 2008-05-16 6:46


$ ghc smp3.hs -O2 -o smp3 --make -threaded
Linking smp3 ...
$ time ./smp3 +RTS -N1
[90,7,7,0,5,63,7,11,31,3]

real    0m1.409s
user    0m1.406s
sys    0m0.002s
$ time ./smp3 +RTS -N2
[90,7,7,0,5,63,7,11,31,3]

real    0m0.834s
user    0m1.564s
sys    0m0.046s
$ time ./smp3 +RTS -N4
[90,7,7,0,5,63,7,11,31,3]

real    0m0.545s
user    0m1.576s
sys    0m0.036s

module Main where
import Data.Maybe
import Control.Parallel.Strategies
import Control.Parallel

factors n = let candidates = [2..floor (sqrt (fromInteger n))]
            in catMaybes $ map (\x ->
                                      if n `mod` x == 0
                                      then Just (x, n `div` x)
                                      else Nothing) candidates
bigNums = [2000000000000..]
answer = (parMap rwhnf) (length . factors) (take 10 bigNums)

main = print answer

Name: Anonymous 2008-05-16 13:21


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List