1
1
module Bench.Data.Map where
2
2
3
3
import Prelude
4
+
4
5
import Control.Monad.Eff (Eff )
5
6
import Control.Monad.Eff.Console (CONSOLE , log )
6
- import Performance.Minibench (bench , benchWith )
7
-
8
- import Data.Tuple (Tuple (..))
7
+ import Data.Foldable (foldl )
8
+ import Data.List (zipWith )
9
9
import Data.List as L
10
10
import Data.Map as M
11
+ import Data.Tuple (Tuple (..))
12
+ import Performance.Minibench (bench , benchWith )
11
13
12
14
benchMap :: Eff (console :: CONSOLE ) Unit
13
15
benchMap = do
@@ -21,15 +23,22 @@ benchMap = do
21
23
log " ------------"
22
24
benchFromFoldable
23
25
26
+ log " "
27
+
28
+ log " foldl"
29
+ log " ------------"
30
+ benchFoldl
31
+
24
32
where
25
33
34
+ nats = L .range 0 999999
35
+ natPairs = zipWith Tuple nats nats
36
+ singletonMap = M .singleton 0 0
37
+ smallMap = M .fromFoldable $ L .take 100 natPairs
38
+ midMap = M .fromFoldable $ L .take 10000 natPairs
39
+ bigMap = M .fromFoldable $ natPairs
40
+
26
41
benchSize = do
27
- let nats = L .range 0 999999
28
- natPairs = (flip Tuple ) unit <$> nats
29
- singletonMap = M .singleton 0 unit
30
- smallMap = M .fromFoldable $ L .take 100 natPairs
31
- midMap = M .fromFoldable $ L .take 10000 natPairs
32
- bigMap = M .fromFoldable $ natPairs
33
42
34
43
log " size: singleton map"
35
44
bench \_ -> M .size singletonMap
@@ -53,3 +62,19 @@ benchMap = do
53
62
54
63
log $ " fromFoldable (" <> show (L .length natPairs) <> " )"
55
64
benchWith 10 \_ -> M .fromFoldable natPairs
65
+
66
+ benchFoldl = do
67
+ let sum = foldl (+) 0
68
+
69
+ log " foldl: singleton map"
70
+ bench \_ -> sum singletonMap
71
+
72
+ log $ " foldl: small map (" <> show (M .size smallMap) <> " )"
73
+ bench \_ -> sum smallMap
74
+
75
+ log $ " foldl: midsize map (" <> show (M .size midMap) <> " )"
76
+ benchWith 100 \_ -> sum midMap
77
+
78
+ log $ " foldl: big map (" <> show (M .size bigMap) <> " )"
79
+ benchWith 10 \_ -> sum bigMap
80
+
0 commit comments