on master help sign in
Merge pull request #1552 from Helkafen/benchmarks
e0f4c37David Christiansen
benchmarks/ALL+1
@@ -1,3 +1,4 @@
1trivial/sortvec 2000
1trivial/sortvec 2000
2quasigroups/qgsolve board
2quasigroups/qgsolve board
3fasta/fasta 1
3fasta/fasta 1
4+pidigits/pidigits 3000
benchmarks/pidigits/pidigits.idrnew file+52
@@ -0,0 +1,52 @@
1+import System
2+
3+{- Toy program that outputs the n first digits of Pi.
4+
5+ Inspired from http://www.haskell.org/haskellwiki/Shootout/Pidigits.
6+ The original ns and str lazy lists have been replaced by strict functions.
7+
8+ Memory usage seems to be excessive. One of the branches of str is tail recursive, and
9+ the other one only needs to cons an extra Integer.
10+
11+ For reference, the Haskell version runs in 0m0.230s when printing to /dev/null.
12+ It almost runs in constant space.
13+-}
14+
15+data F = mkF Integer Integer Integer
16+
17+-- Prints the list of digits by groups of 10
18+loop : Nat -> Nat -> List Integer -> IO()
19+loop n k' Nil = putStrLn $ (pack $ Vect.replicate n ' ') ++ "\t:" ++ show k'
20+loop Z k' xs = do putStrLn ("\t:"++show k')
21+ loop 10 k' xs
22+loop (S k) k' (x::xs) = do putStr (show x)
23+ loop k (S k') xs
24+
25+fn : Integer -> F
26+fn k = mkF k (4*k+2) (2*k+1)
27+
28+flr : Integer -> F -> Integer
29+flr x (mkF q r t) = (q*x + r) `div` t
30+
31+comp : F -> F -> F
32+comp (mkF q r t) (mkF u v x) = mkF (q*u) (q*v+r*x) (t*x)
33+
34+-- Returns the list of digits of pi. Memory hungry.
35+str : F -> Integer -> Nat -> List Integer
36+str _ _ Z = Nil
37+str z k (S n) = if(y == flr 4 z)
38+ then y :: str (comp (mkF 10 (-10*y) 1) z ) k n
39+ else str (comp z (fn k)) (k+1) (S n)
40+ where y = flr 3 z
41+
42+pidigit : IO()
43+pidigit = do
44+ [_,a] <- getArgs
45+ let n = fromIntegerNat (the Integer (cast a))
46+ let l = str (mkF 1 0 1) 1 n
47+ loop 10 0 l
48+ return ()
49+
50+main : IO ()
51+main = pidigit
52+
benchmarks/pidigits/pidigits.ipkgnew file+6
@@ -0,0 +1,6 @@
1+package pidigits
2+
3+modules = pidigits
4+
5+executable = pidigits
6+main = pidigits