[Shootout-list] Faster nestedloop for ghc

Tomasz Zielonka t.zielonka@students.mimuw.edu.pl
Wed, 29 Sep 2004 19:59:16 +0200


--rwEMma7ioTxnRzrJ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello!

The speed improvement (about 7x) is achieved by using a bounded integer
type Int for the counter (x) instead of unbounded Integer.

I also restructured code is such a way that there is no need for passing
the number of iterations (now m) around.

Also, -fglasgow-exts is not necessary now.

Compile with -O or -O2.

Best regards,
Tom

-- 
.signature: Too many levels of symbolic links

--rwEMma7ioTxnRzrJ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="nest1.hs"

-- $Id: nestedloop.ghc.html,v 1.5 2004/07/03 07:11:31 bfulgham Exp $
-- http://www.bagley.org/~doug/shootout/
-- from Brian Gregor
-- shortened by JP Bernardy
-- simplified and optimised by Tomasz Zielonka

import System(getArgs)

main :: IO ()
main = do [number] <- getArgs
	  let m :: Int; m = read number

              loopA 0 x = x
	      loopA n x = loopA (n-1) (loopB m x)

	      loopB 0 x = x
	      loopB n x = loopB (n-1) (loopC m x)

	      loopC 0 x = x
	      loopC n x = loopC (n-1) (loopD m x)

	      loopD 0 x = x
	      loopD n x = loopD (n-1) (loopE m x)

	      loopE 0 x = x
	      loopE n x = loopE (n-1) (loopF m x)

	      loopF 0 x = x
	      loopF n x = loopF (n-1) (x+1)
          
          putStrLn (show (loopA m (0 :: Int)))


--rwEMma7ioTxnRzrJ--