perf test for Word->Float/Double conversion
authorJohan Tibell <johan.tibell@gmail.com>
Tue, 18 Dec 2012 13:40:02 +0000 (14:40 +0100)
committerJohan Tibell <johan.tibell@gmail.com>
Tue, 18 Dec 2012 13:40:24 +0000 (14:40 +0100)
testsuite/tests/perf/should_run/Conversions.hs [new file with mode: 0644]
testsuite/tests/perf/should_run/Conversions.stdout [new file with mode: 0644]
testsuite/tests/perf/should_run/all.T

diff --git a/testsuite/tests/perf/should_run/Conversions.hs b/testsuite/tests/perf/should_run/Conversions.hs
new file mode 100644 (file)
index 0000000..8432727
--- /dev/null
@@ -0,0 +1,21 @@
+{-# LANGUAGE BangPatterns #-}
+
+-- | Tests that conversions between various primitive types (e.g.
+-- Word, Double, etc) doesn't allocate.
+module Main (main) where
+
+import Data.Word
+
+-- Repeatedly convert Words to Doubles
+loop :: Floating a => Word -> a
+loop n = go 0 0.0
+  where
+    go i !acc | i < n = go (i+1) (acc + fromIntegral i)
+              | otherwise = acc
+{-# SPECIALISE loop :: Word -> Float #-}
+{-# SPECIALISE loop :: Word -> Double #-}
+
+main :: IO ()
+main = do
+    print (loop 1000000 :: Float)
+    print (loop 1000000 :: Double)
diff --git a/testsuite/tests/perf/should_run/Conversions.stdout b/testsuite/tests/perf/should_run/Conversions.stdout
new file mode 100644 (file)
index 0000000..2fe5b4d
--- /dev/null
@@ -0,0 +1,2 @@
+4.9994036e11
+4.999995e11
index 7bfd8aa..2fa0582 100644 (file)
@@ -254,3 +254,15 @@ test('T7257',
       only_ways(['normal'])
      ],
     compile_and_run, ['-O'])
+
+test('Conversions',
+     [if_wordsize(32,
+          stats_range_field('bytes allocated', 55316, 5)),
+                           # 2012-12-18: Guessed 64-bit value / 2
+      if_wordsize(64,
+          stats_range_field('bytes allocated', 110632, 5)),
+                           # 2012-12-18: 109608 (amd64/OS X)
+
+      only_ways(['normal'])
+     ],
+    compile_and_run, ['-O'])