mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-09-11 08:55:23 +03:00
Add benchmark pidigits
Memory usage is quite high
This commit is contained in:
parent
20b02c5996
commit
6e9ae3e176
@ -1,3 +1,4 @@
|
||||
trivial/sortvec 2000
|
||||
quasigroups/qgsolve board
|
||||
fasta/fasta 1
|
||||
pidigits/pidigits 3000
|
||||
|
38
benchmarks/pidigits/pidigits.idr
Normal file
38
benchmarks/pidigits/pidigits.idr
Normal file
@ -0,0 +1,38 @@
|
||||
import System
|
||||
|
||||
data F = mkF Integer Integer Integer
|
||||
|
||||
loop : Nat -> Nat -> List Integer -> IO()
|
||||
loop n k' Nil = putStrLn $ (pack $ Vect.replicate n ' ') ++ "\t:" ++ show k'
|
||||
loop Z k' xs = do putStrLn ("\t:"++show k')
|
||||
loop 10 k' xs
|
||||
loop (S k) k' (x::xs) = do putStr (show x)
|
||||
loop k (S k') xs
|
||||
|
||||
fn : Integer -> F
|
||||
fn k = mkF k (4*k+2) (2*k+1)
|
||||
|
||||
flr : Integer -> F -> Integer
|
||||
flr x (mkF q r t) = (q*x + r) `div` t
|
||||
|
||||
comp : F -> F -> F
|
||||
comp (mkF q r t) (mkF u v x) = mkF (q*u) (q*v+r*x) (t*x)
|
||||
|
||||
str : F -> Integer -> Nat -> List Integer
|
||||
str _ _ Z = Nil
|
||||
str z k (S n) = if(y == flr 4 z)
|
||||
then y :: str (comp (mkF 10 (-10*y) 1) z ) k n
|
||||
else str (comp z (fn k)) (k+1) (S n)
|
||||
where y = flr 3 z
|
||||
|
||||
pidigit : IO()
|
||||
pidigit = do
|
||||
[_,a] <- getArgs
|
||||
let n = fromIntegerNat (the Integer (cast a))
|
||||
let l = str (mkF 1 0 1) 1 n
|
||||
loop 10 0 l
|
||||
return ()
|
||||
|
||||
main : IO ()
|
||||
main = pidigit
|
||||
|
6
benchmarks/pidigits/pidigits.ipkg
Normal file
6
benchmarks/pidigits/pidigits.ipkg
Normal file
@ -0,0 +1,6 @@
|
||||
package pidigits
|
||||
|
||||
modules = pidigits
|
||||
|
||||
executable = pidigits
|
||||
main = pidigits
|
Loading…
Reference in New Issue
Block a user