summaryrefslogtreecommitdiff
path: root/utils/benchmarks/events/IntMap.hs
diff options
context:
space:
mode:
authorAlina Banerjee <alina@glitchgirl.us>2021-07-19 03:59:12 +0000
committerAlina Banerjee <alina@glitchgirl.us>2021-07-19 22:38:29 +0000
commitc708b969bafb403d482565601f8d0ed963e54a3c (patch)
tree81ea1c9f198a34af8807b2765311d54293b4648b /utils/benchmarks/events/IntMap.hs
parentde9fedc380d22ff6db3e4c7540af07b99d26fbd9 (diff)
downloadhaskell-wip/fix-8045.tar.gz
Move event benchmarks to utils/benchmarks/events/wip/fix-8045
Diffstat (limited to 'utils/benchmarks/events/IntMap.hs')
-rw-r--r--utils/benchmarks/events/IntMap.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/utils/benchmarks/events/IntMap.hs b/utils/benchmarks/events/IntMap.hs
new file mode 100644
index 0000000000..0313de4e87
--- /dev/null
+++ b/utils/benchmarks/events/IntMap.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE BangPatterns #-}
+module Main where
+
+import Criterion.Main
+import Data.IntMap.Strict (IntMap)
+import qualified Data.IntMap.Strict as IM
+
+main = defaultMain
+ [ bench "insert10k" $ whnf ascFrom n
+ ]
+ where
+ -- Number of elements
+ n = 10000
+
+-- | Create an integer map with keys in ascending order starting at 0
+-- and ending at @max@ (exclusive.)
+ascFrom :: Int -> IntMap Int
+ascFrom max = go 0 IM.empty
+ where
+ go :: Int -> IntMap Int -> IntMap Int
+ go n !mp
+ | n >= max = mp
+ | otherwise = let !mp' = IM.insertWith const n n mp
+ in go (n + 1) mp'