summaryrefslogtreecommitdiff
path: root/utils/benchmarks/IntMap.hs
blob: 0313de4e8727bf0d5d018f5b01cd6d8ddb7119f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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'