summaryrefslogtreecommitdiff
path: root/utils/benchmarks/events/IntMap.hs
diff options
context:
space:
mode:
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'