summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2022-12-02 16:46:45 +0100
committerSebastian Graf <sebastian.graf@kit.edu>2022-12-06 16:23:53 +0100
commit4bb308efc01bf290269d776c74deb4ede7b24902 (patch)
treeb7b00e163463a26cfb5d088eb9d877f75b215ed2 /testsuite/tests/perf/should_run
parenta9d9b8c0458e838f331ead62dca272665ecbf20d (diff)
downloadhaskell-4bb308efc01bf290269d776c74deb4ede7b24902.tar.gz
Make `drop` and `dropWhile` fuse (#18964)wip/T18964
I copied the fusion framework we have in place for `take`. T18964 asserts that we regress neither when fusion fires nor when it doesn't. Fixes #18964.
Diffstat (limited to 'testsuite/tests/perf/should_run')
-rw-r--r--testsuite/tests/perf/should_run/T18964.hs15
-rw-r--r--testsuite/tests/perf/should_run/T18964.stdout4
-rw-r--r--testsuite/tests/perf/should_run/all.T2
3 files changed, 21 insertions, 0 deletions
diff --git a/testsuite/tests/perf/should_run/T18964.hs b/testsuite/tests/perf/should_run/T18964.hs
new file mode 100644
index 0000000000..e9c7b915e7
--- /dev/null
+++ b/testsuite/tests/perf/should_run/T18964.hs
@@ -0,0 +1,15 @@
+import GHC.Exts
+import Data.Int
+
+main :: IO ()
+main = do
+ -- drop should fuse away and the program should consume O(1) space
+ -- If fusion fails, this allocates about 640MB.
+ print $ sum $ drop 10 [0..10000000::Int64]
+ -- Here, drop can't fuse. This asserts that we don't regress in allocations in that case either
+ -- If we don't do a good job here, we'll see more than 6.4MB of allocs.
+ print $ lazy $ sum $ lazy $ drop 10 $ lazy [0..100000::Int64]
+
+ -- and once more with dropWhile
+ print $ sum $ dropWhile (< 10) [0..10000000::Int64]
+ print $ lazy $ sum $ lazy $ dropWhile (< 10) $ lazy [0..100000::Int64]
diff --git a/testsuite/tests/perf/should_run/T18964.stdout b/testsuite/tests/perf/should_run/T18964.stdout
new file mode 100644
index 0000000000..b1c0d38f19
--- /dev/null
+++ b/testsuite/tests/perf/should_run/T18964.stdout
@@ -0,0 +1,4 @@
+50000004999955
+5000049955
+50000004999955
+5000049955
diff --git a/testsuite/tests/perf/should_run/all.T b/testsuite/tests/perf/should_run/all.T
index 59ad878a4c..ba75906c7d 100644
--- a/testsuite/tests/perf/should_run/all.T
+++ b/testsuite/tests/perf/should_run/all.T
@@ -408,3 +408,5 @@ test('T21839r',
only_ways(['normal'])],
compile_and_run,
['-O'])
+
+test('T18964', [collect_stats('bytes allocated', 1), only_ways(['normal'])], compile_and_run, ['-O'])