I forgot about Java.
But, it's still here.
Here are some factorial timings.
It was run using Java 1.6, from within NetBeans 7.0.
(I agree, the times are strange.)
' code ------------------------------------------------------------------------------------------------- package fact; import java.math.BigInteger; public class Fact { public static BigInteger factorial(int n) { BigInteger product; int i; product = BigInteger.valueOf(1); for (i = 2; i <= n; i++) { product = product.multiply(BigInteger.valueOf(i)); } return product; } public static void main(String[] args) { BigInteger value; long start, stop; double seconds; int i, j; System.out.println("n! seconds"); for (i = 1; i <= 20; i++) { j = i * 10000; start = System.currentTimeMillis(); value = factorial(j); stop = System.currentTimeMillis(); seconds = (stop - start) / 1000.0; System.out.printf("%06d %07.3f\n", j, seconds); } } } ' output ----------------------------------------------------------------------------------------------- n! seconds 010000 000.768 020000 003.198 030000 007.302 040000 013.405 050000 021.158 060000 032.471 070000 044.814 080000 059.941 090000 075.980 100000 093.814 110000 116.617 120000 136.939 130000 159.905 140000 186.705 150000 313.046 160000 292.847 170000 282.498 180000 325.723 190000 359.425 200000 397.941
Bookmarks