summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Tibell <johan.tibell@gmail.com>2012-12-18 14:40:02 +0100
committerJohan Tibell <johan.tibell@gmail.com>2012-12-18 14:40:24 +0100
commit8cd4ced57dccc1f4f54d242982209ec61e145700 (patch)
tree9643a77d094eadaa26b4101a6d0ef5699255261d
parentcf240aa067b68c2d1327760ce1a3c2dfc7b061e7 (diff)
downloadhaskell-8cd4ced57dccc1f4f54d242982209ec61e145700.tar.gz
perf test for Word->Float/Double conversion
-rw-r--r--testsuite/tests/perf/should_run/Conversions.hs21
-rw-r--r--testsuite/tests/perf/should_run/Conversions.stdout2
-rw-r--r--testsuite/tests/perf/should_run/all.T12
3 files changed, 35 insertions, 0 deletions
diff --git a/testsuite/tests/perf/should_run/Conversions.hs b/testsuite/tests/perf/should_run/Conversions.hs
new file mode 100644
index 0000000000..8432727965
--- /dev/null
+++ b/testsuite/tests/perf/should_run/Conversions.hs
@@ -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
index 0000000000..2fe5b4dc9d
--- /dev/null
+++ b/testsuite/tests/perf/should_run/Conversions.stdout
@@ -0,0 +1,2 @@
+4.9994036e11
+4.999995e11
diff --git a/testsuite/tests/perf/should_run/all.T b/testsuite/tests/perf/should_run/all.T
index 7bfd8aaa17..2fa0582771 100644
--- a/testsuite/tests/perf/should_run/all.T
+++ b/testsuite/tests/perf/should_run/all.T
@@ -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'])