Move CPUTime001 here from testsuite/tests/lib/CPUTime
authorIan Lynagh <igloo@earth.li>
Sat, 19 Nov 2011 21:36:10 +0000 (21:36 +0000)
committerIan Lynagh <igloo@earth.li>
Sat, 19 Nov 2011 21:36:10 +0000 (21:36 +0000)
tests/CPUTime001.hs [new file with mode: 0644]
tests/CPUTime001.stdout [new file with mode: 0644]
tests/all.T

diff --git a/tests/CPUTime001.hs b/tests/CPUTime001.hs
new file mode 100644 (file)
index 0000000..6c43c57
--- /dev/null
@@ -0,0 +1,26 @@
+-- !!! Test getCPUTime
+
+import System.CPUTime
+import System.IO
+
+main :: IO ()
+main = do
+    t28 <- timeFib 28
+    t29 <- timeFib 29
+    t30 <- timeFib 30
+    print (t28 <= t29, t29 <= t30)
+
+timeFib :: Integer -> IO Integer
+timeFib n = do
+    start <- getCPUTime
+    print (nfib n)
+    end <- getCPUTime
+    return (end - start)
+
+nfib :: Integer -> Integer
+nfib n 
+  | n <= 1 = 1
+  | otherwise = (n1 + n2 + 1)
+  where 
+    n1 = nfib (n-1) 
+    n2 = nfib (n-2)
diff --git a/tests/CPUTime001.stdout b/tests/CPUTime001.stdout
new file mode 100644 (file)
index 0000000..032e759
--- /dev/null
@@ -0,0 +1,4 @@
+1028457
+1664079
+2692537
+(True,True)
index 7c9fc6e..a55ad83 100644 (file)
@@ -6,3 +6,4 @@ test('tempfiles', normal, compile_and_run, [''])
 test('fixed', normal, compile_and_run, [''])
 test('quotOverflow', normal, compile_and_run, [''])
 test('assert', exit_code(1), compile_and_run, ['-fno-ignore-asserts'])
+test('CPUTime001', normal, compile_and_run, [''])