[MLton] factorial of 1,000,000

Stephen Weeks MLton@mlton.org
Mon, 28 Jun 2004 10:10:21 -0700


There was a recent discussion at meme.b9.com about computing factorial
of 1,000,000 iteratively.

	http://meme.b9.com/cview.html?channel=scheme&date=040626

I tried it out in MLton on my 1.6GHz machine.  It took 207 minutes,
with 2.5% gc time.  Here were the gc stats

total allocated: 1,200,666,893,648 bytes
max live: 2,322,468 bytes
max semispace: 64,802,816 bytes
max stack size: 264 bytes

The result was 5,565,709 digits.


For completeness, here's the program that I used.

fun iter (x: IntInf.int, i) =
   if x < 2
      then i
   else iter (x - 1, x * i)

fun fact x = iter (x, 1)

val _ = print (concat [IntInf.toString (fact 1000000), "\n"])