on master help sign in
Clear out current benchmarks for a more targeted benchmark suite
e4dad2bEvan Czaplicki
.gitignore+1
@@ -1,3 +1,4 @@
1+elm-stuff
1dist
2dist
2cabal-dev
3cabal-dev
3.cabal-sandbox/
4.cabal-sandbox/
bench/CompilerBenchmarks.elmdeleted−165
@@ -1,165 +0,0 @@
1−import Graphics.Element exposing (show)
2−import Signal
3−import Benchmark
4−import Task exposing (Task, andThen)
5−import Text
6−import Array
7−import Random
8−import Dict
9−import Time
10−
11−import LargeDictionary
12−import ArrayBench
13−import ListBench
14−
15−import RecordBench
16−import SmallRecordBench
17−import TupleBench
18−import SmallTupleBench
19−import CtorBench
20−import SmallCtorBench
21−import PatternMatchBench
22−import IfBench
23−import DictBench
24−
25−import AnimateBench
26−import TodoBench
27−
28−{-| Compile this with --output=Benchmarks.html to generate
29− a webpage, which runs the benchmarks and shows the results.
30−-}
31−
32−
33−mySuite =
34− Benchmark.Suite "My Suite"
35− [ Benchmark.bench1 "Access 20-field record 200 times: " RecordBench.sumRandomElems indices200
36− , Benchmark.bench1 "Access 9-field record 200 times: " SmallRecordBench.sumRandomElems indices200
37−
38− , Benchmark.bench1 "Access 9-field tuple 200 times: " TupleBench.sumRandomElems indices200
39− , Benchmark.bench1 "Access 3-field tuple 200 times: " SmallTupleBench.sumRandomElems indices200
40−
41− , Benchmark.bench1 "Access 20-constructor Type 200 times: " CtorBench.sumFieldsList ctorData200
42− , Benchmark.bench1 "Access 10-constructor Type 200 times: " SmallCtorBench.sumFieldsList smallCtorData200
43−
44− , Benchmark.bench1 "Tail-recursive if function, called 200 times: " IfBench.tailRecSum indices200
45− , Benchmark.bench1 "If expression with 20 branches, called 200 times: " IfBench.manyConditionalSum indices200
46− , Benchmark.bench1 "If expression with 4 branches, called 200 times: " IfBench.fewConditionalSum indices200
47−
48− , Benchmark.bench1 "Pattern match 18-levels deep, use all values, 200 times " PatternMatchBench.deepMatchSum nestedData200
49− , Benchmark.bench1 "Pattern match 18-levels deep, 16 wildcards, 200 times " PatternMatchBench.wildcardMatchSum nestedData200
50− , Benchmark.bench1 "Pattern match 4-levels deep, use all values, 200 times " PatternMatchBench.shallowMatchSum nestedData200
51−
52− , Benchmark.bench1 "Make and sum dict, 10000 elems: " LargeDictionary.addNToDictAndSum 10000
53− , Benchmark.bench1 "Make and sum dict, 50 elems: " LargeDictionary.addNToDictAndSum 50
54−
55− , Benchmark.bench1 "Array native foldr, 500 elems: " ArrayBench.foldrMeanStddev array500
56− , Benchmark.bench1 "Array native foldl, 500 elems: " ArrayBench.foldlMeanStddev array500
57− , Benchmark.bench1 "Array custom foldr, 500 elems: " ArrayBench.customFoldrMeanStddev array500
58− , Benchmark.bench1 "Array custom foldl, 500 elems: " ArrayBench.customFoldrMeanStddev array500
59− , Benchmark.bench3 "Array square nth elem, 500 elems: " ArrayBench.updateNRandomIndices (\x -> x*x) indices200 array500
60−
61− , Benchmark.bench1 "Dict native foldr, 500 elems: " DictBench.foldrMeanStddev dict500
62− , Benchmark.bench1 "Dict native foldl, 500 elems: " DictBench.foldlMeanStddev dict500
63− , Benchmark.bench3 "Dict square nth elem, 500 elems: " DictBench.updateNRandomIndices (\x -> x*x) indices200 dict500
64−
65− , Benchmark.bench1 "List native foldr, 500 elems: " ListBench.foldrMeanStddev list500
66− , Benchmark.bench1 "List native foldl, 500 elems: " ListBench.foldlMeanStddev list500
67− , Benchmark.bench1 "List custom foldr, 500 elems: " ListBench.customFoldrMeanStddev list500
68− , Benchmark.bench1 "List custom foldl, 500 elems: " ListBench.customFoldrMeanStddev list500
69− , Benchmark.bench3 "List square nth elem, 500 elems: " ListBench.updateNRandomIndices (\x -> x*x) indices200 list500
70−
71− , Benchmark.bench2 "200 lookups in array of 500 elems: " ArrayBench.randomLookups indices200 (Array.fromList [1 .. 500] )
72− , Benchmark.bench2 "200 lookups in list of 500 elems: " ListBench.randomLookups indices200 ([1 .. 500] )
73− , Benchmark.bench2 "200 lookups in dict of 500 elems: " DictBench.randomLookups indices200 (Dict.fromList (List.map2 (,) [1 .. 500] [1 .. 500]) )
74−
75− , Benchmark.bench1 "30s simulated animation @ 30fps: " AnimateBench.runAnimation timeSteps30s
76− , Benchmark.bench1 "TodoMVC: approx. 330 simulated actions " TodoBench.evalActions TodoBench.testActions
77− ]
78−
79−
80−--Display of results:
81−
82−--Mailbox updated with benchmark run progress
83−results : Signal.Mailbox String
84−results =
85− Signal.mailbox "Benchmark loading"
86−
87−
88−--The actual task which runs the benchmarks
89−port benchResults : (Task Benchmark.Never ())
90−port benchResults =
91− Benchmark.runWithProgress (Just results) mySuite
92− `andThen` \_ -> Task.sleep 0
93−
94−
95−--Our main page:
96−main =
97− Signal.map (Graphics.Element.leftAligned << Text.fromString) results.signal
98−
99−
100−
101−-- Random generation and structures
102−
103−--Maximum size for random numbers
104−maxSize = 1000000
105−
106−
107−--Random generator for floating point numbers
108−floatGen =
109− Random.float (-1 * maxSize) (maxSize)
110−
111−
112−--Generate random indices for lists out of 500 elements
113−indexGen =
114− Random.int (0) (499)
115−
116−
117−--Random seeds: they're fixed, so it's not truly random
118−--But we get seemingly random data, that we can compare fairly
119−--across multiple runs of the benchmark
120−
121−--seed for our index generation
122−indexSeed =
123− Random.initialSeed 56
124−
125−
126−--Seed for our float generation
127−seed =
128− Random.initialSeed 23
129−
130−
131−--Pseudo-random array of 500 floating point numbers
132−array500 =
133− (ArrayBench.randomArray floatGen 500 seed)
134−
135−
136−--Pseudo-random dictionary, indexed 0 .. 500, of 500 floating point numbers
137−dict500 =
138− (DictBench.randomDict floatGen 500 seed)
139−
140−
141−
142−--Same contents as array500, but in list form
143−list500 =
144− (ListBench.randomList floatGen 500 seed)
145−
146−
147−--Pseudo random list of 200 indices between 0 and 499
148−indices200 =
149− (ListBench.randomList indexGen 200 indexSeed)
150−
151−
152−--List of timesteps simulating 30 seconds of animation at 30fps
153−timeSteps30s =
154− List.map (\x -> (1.0 / 30.0) * (toFloat x * Time.second) ) [1 .. 900]
155−
156−ctorData200 =
157− List.map CtorBench.makeRandomData indices200
158−
159−
160−smallCtorData200 =
161− List.map SmallCtorBench.makeRandomData indices200
162−
163−
164−nestedData200 =
165− List.map PatternMatchBench.intToNest indices200
bench/src/AnimateBench.elmdeleted−58
@@ -1,58 +0,0 @@
1−module AnimateBench where
2−
3−import Time exposing (Time)
4−
5−
6−{-| Main Spring Type.
7−A spring's behavior is defined by its stiffness and damping parameters.
8−-}
9−type alias Spring a =
10− { stiffness : Float
11− , damping : Float
12− , position : a
13− , velocity : a
14− , destination : a
15− }
16−
17−
18−defaultSpring =
19− Spring 1.0 0.5 0.0 1.0 100.0
20−
21−
22−epsilon = 0.0001
23−
24−
25−{-| Animate a spring given a framerate.
26−
27− animate framerate spring
28−-}
29−animate : Time -> Spring Float -> Spring Float
30−animate fpms spring =
31− let
32− frameRate = fpms / 1000
33−
34− fspring = -spring.stiffness * (spring.position - spring.destination)
35−
36− fdamper = -spring.damping * spring.velocity
37−
38− a = fspring + fdamper
39−
40− newV = spring.velocity + a * frameRate
41− newX = spring.position + newV * frameRate
42− in
43− if
44− abs (newV - spring.velocity) < epsilon && abs (newX - spring.position) < epsilon
45− then
46− { spring | position <- spring.destination
47− , velocity <- 0
48− }
49− else
50− { spring | position <- newX
51− , velocity <- newV
52− }
53−
54−
55−
56−runAnimation : List Float -> Spring Float
57−runAnimation timeSteps =
58− List.foldr animate defaultSpring timeSteps
bench/src/ArrayBench.elmdeleted−94
@@ -1,94 +0,0 @@
1−module ArrayBench where
2−
3−import Array
4−import Random
5−import Debug exposing (crash)
6−
7−
8−
9−randomArray
10− : Random.Generator a
11− -> Int
12− -> Random.Seed
13− -> Array.Array a
14−randomArray gen n initSeed =
15− let
16− f n (seed, accum) =
17− let
18− (nextToAdd, newSeed) = Random.generate gen seed
19− newAccum = Array.push nextToAdd accum
20− in (newSeed, newAccum)
21− in
22− snd <| List.foldl f (initSeed, Array.empty) [1 .. n]
23−
24−meanAndStddev
25− : ((Float -> (Float, Float) -> (Float, Float)) -> (Float, Float) -> Array.Array Float -> (Float, Float))
26− -> Array.Array Float
27− -> (Float, Float)
28−meanAndStddev foldFn ourArray =
29− let
30− --ourArray = randomArray n (Random.initialSeed 23)
31− (theSum, sumSq) = foldFn (\x (sum, sumSq) -> (x + sum, (x^2) + sumSq) ) (0,0) ourArray
32− in
33− (theSum, sqrt(theSum*theSum - sumSq))
34−
35−
36−foldrMeanStddev = meanAndStddev Array.foldr
37−
38−
39−foldlMeanStddev = meanAndStddev Array.foldl
40−
41−
42−customFoldrMeanStddev = meanAndStddev myFoldr
43−
44−
45−customFoldlMeanStddev = meanAndStddev myFoldl
46−
47−
48−updateNRandomIndices
49− : (Float -> Float)
50− -> List Int
51− -> Array.Array Float
52− -> Array.Array Float
53−updateNRandomIndices f indexList startList =
54− List.foldr
55− (\ i oldList -> updateN i f oldList)
56− startList indexList
57−
58−
59−randomLookups : List Int -> Array.Array Float -> List (Maybe Float)
60−randomLookups indices arr =
61− List.map (\i -> Array.get i arr) indices
62−
63−
64−myFoldl : (a -> b -> b) -> b -> Array.Array a -> b
65−myFoldl f init arr =
66− let
67− len = Array.length arr
68− fromJust (Just x) = x
69− helper init i =
70− if (i >= len)
71− then init
72− else
73− helper (f (fromJust <| Array.get i arr) init) (i+1)
74− in helper init 0
75−
76−
77−myFoldr : (a -> b -> b) -> b -> Array.Array a -> b
78−myFoldr f init arr =
79− let
80− len = Array.length arr
81− fromJust (Just x) = x
82− helper init i =
83− if (i <= 0)
84− then init
85− else
86− helper (f (fromJust <| Array.get i arr) init) (i-1)
87− in helper init (len-1)
88−
89−
90−updateN : Int -> (a -> a) -> Array.Array a -> Array.Array a
91−updateN n f arr =
92− case Array.get n arr of
93− Just x -> Array.set n (f x) arr
94− _ -> crash "Array out of bounds"
bench/src/CtorBench.elmdeleted−135
@@ -1,135 +0,0 @@
1−module CtorBench where
2−
3−type ManyCtors =
4− MyLongNamedCtor1 Float Float Float
5− | MyLongNamedCtor2 Float Float
6− | MyLongNamedCtor3 Float Float Float
7− | MyLongNamedCtor4 Float Float
8− | MyLongNamedCtor5 Float Float Float
9− | MyLongNamedCtor6 Float Float
10− | MyLongNamedCtor7 Float Float Float
11− | MyLongNamedCtor8 Float Float
12− | MyLongNamedCtor9 Float Float Float
13− | MyLongNamedCtor10 Float Float
14− | MyLongNamedCtor11 Float Float Float
15− | MyLongNamedCtor12 Float Float
16− | MyLongNamedCtor13 Float Float Float
17− | MyLongNamedCtor14 Float Float
18− | MyLongNamedCtor15 Float Float Float
19− | MyLongNamedCtor16 Float Float
20− | MyLongNamedCtor17 Float Float Float
21− | MyLongNamedCtor18 Float Float
22− | MyLongNamedCtor19 Float Float Float
23− | MyLongNamedCtor20 Float Float
24−
25−
26−getFieldSum someData =
27− case someData of
28− MyLongNamedCtor1 x y z ->
29− x + y + z
30−
31− MyLongNamedCtor3 x y z ->
32− x + y + z
33−
34− MyLongNamedCtor5 x y z ->
35− x + y + z
36−
37− MyLongNamedCtor7 x y z ->
38− x + y + z
39−
40− MyLongNamedCtor9 x y z ->
41− x + y + z
42−
43− MyLongNamedCtor11 x y z ->
44− x + y + z
45−
46− MyLongNamedCtor13 x y z ->
47− x + y + z
48−
49− MyLongNamedCtor15 x y z ->
50− x + y + z
51−
52− MyLongNamedCtor17 x y z ->
53− x + y + z
54−
55− MyLongNamedCtor19 x y z ->
56− x + y + z
57−
58− MyLongNamedCtor20 x y ->
59− x + y
60−
61− MyLongNamedCtor18 x y ->
62− x + y
63−
64− MyLongNamedCtor16 x y ->
65− x + y
66−
67− MyLongNamedCtor14 x y ->
68− x + y
69−
70− MyLongNamedCtor12 x y ->
71− x + y
72−
73− MyLongNamedCtor10 x y ->
74− x + y
75−
76− MyLongNamedCtor8 x y ->
77− x + y
78−
79− MyLongNamedCtor6 x y ->
80− x + y
81−
82− MyLongNamedCtor4 x y ->
83− x + y
84−
85− MyLongNamedCtor2 x y ->
86− x + y
87−
88−
89−makeRandomData i =
90− case (i % 20) of
91− 0 ->
92− MyLongNamedCtor20 (toFloat i) (toFloat <| i*i)
93− 1 ->
94− MyLongNamedCtor1 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
95− 2 ->
96− MyLongNamedCtor2 (toFloat i) (toFloat <| i*i)
97− 3 ->
98− MyLongNamedCtor3 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
99− 4 ->
100− MyLongNamedCtor4 (toFloat i) (toFloat <| i*i)
101− 5 ->
102− MyLongNamedCtor5 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
103− 6 ->
104− MyLongNamedCtor6 (toFloat i) (toFloat <| i*i)
105− 7 ->
106− MyLongNamedCtor7 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
107− 8 ->
108− MyLongNamedCtor8 (toFloat i) (toFloat <| i*i)
109− 9 ->
110− MyLongNamedCtor9 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
111− 10 ->
112− MyLongNamedCtor10 (toFloat i) (toFloat <| i*i)
113− 11 ->
114− MyLongNamedCtor11 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
115− 12 ->
116− MyLongNamedCtor12 (toFloat i) (toFloat <| i*i)
117− 13 ->
118− MyLongNamedCtor13 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
119− 14 ->
120− MyLongNamedCtor14 (toFloat i) (toFloat <| i*i)
121− 15 ->
122− MyLongNamedCtor15 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
123− 16 ->
124− MyLongNamedCtor16 (toFloat i) (toFloat <| i*i)
125− 17 ->
126− MyLongNamedCtor17 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
127− 18 ->
128− MyLongNamedCtor18 (toFloat i) (toFloat <| i*i)
129− 19 ->
130− MyLongNamedCtor19 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
131−
132−
133−sumFieldsList : List ManyCtors -> Float
134−sumFieldsList dataList =
135− List.foldr (\val sumSoFar -> (getFieldSum val) + sumSoFar ) 0.0 dataList
bench/src/DictBench.elmdeleted−63
@@ -1,63 +0,0 @@
1−module DictBench where
2−
3−import Dict
4−import Random
5−import Debug exposing (crash)
6−
7−
8−
9−randomDict
10− : Random.Generator a
11− -> Int
12− -> Random.Seed
13− -> Dict.Dict Int a
14−randomDict gen n initSeed =
15− let
16− f n (seed, accum) =
17− let
18− (nextToAdd, newSeed) = Random.generate gen seed
19− newAccum = Dict.insert n nextToAdd accum
20− in (newSeed, newAccum)
21− in
22− snd <| List.foldl f (initSeed, Dict.empty) [1 .. n]
23−
24−meanAndStddev
25− : ((Int -> Float -> (Float, Float) -> (Float, Float)) -> (Float, Float) -> Dict.Dict Int Float -> (Float, Float))
26− -> Dict.Dict Int Float
27− -> (Float, Float)
28−meanAndStddev foldFn ourDict =
29− let
30− --ourDict = randomDict n (Random.initialSeed 23)
31− (theSum, sumSq) = foldFn (\_ x (sum, sumSq) -> (x + sum, (x^2) + sumSq) ) (0,0) ourDict
32− in
33− (theSum, sqrt(theSum*theSum - sumSq))
34−
35−
36−foldrMeanStddev = meanAndStddev Dict.foldr
37−
38−
39−foldlMeanStddev = meanAndStddev Dict.foldl
40−
41−
42−updateNRandomIndices
43− : (Float -> Float)
44− -> List Int
45− -> Dict.Dict Int Float
46− -> Dict.Dict Int Float
47−updateNRandomIndices f indexList startList =
48− List.foldr
49− (\ i oldList -> updateN i f oldList)
50− startList indexList
51−
52−
53−randomLookups : List Int -> Dict.Dict Int Float -> List (Maybe Float)
54−randomLookups indices arr =
55− List.map (\i -> Dict.get i arr) indices
56−
57−
58−
59−updateN : Int -> (a -> a) -> Dict.Dict Int a -> Dict.Dict Int a
60−updateN n f arr =
61− case Dict.get n arr of
62− Just x -> Dict.insert n (f x) arr
63− _ -> crash "Dict out of bounds"
bench/src/IfBench.elmdeleted−104
@@ -1,104 +0,0 @@
1−module IfBench where
2−
3−
4−tailRecursiveIfFn : Int -> Float
5−tailRecursiveIfFn i =
6− if i < 0 then
7− 10.0
8−
9− else if i == 0 then
10− 20.0
11−
12− else if i > 0 && i < 10 then
13− 30.0
14−
15− else
16− tailRecursiveIfFn (i - (1 + (i % 5)))
17−
18−
19−manyConditionFunction i =
20− if i <= 0 then
21− 30.0 + (toFloat i)
22−
23− else if i > 100 && (i * i) % 20 == 7 then
24− 24.3 + (toFloat i)
25−
26− else if i > 100 && (i % 3 == 1) then
27− 3.33 + (toFloat i)
28−
29− else if i == 152 then
30− 29.0 + (toFloat i)
31−
32− else if i + (i*i) > 200 && (i + (i*i) < 300) then
33− 32.9 + (toFloat i)
34−
35− else if i == 99 then
36− 93.0 + (toFloat i)
37−
38− else if i*i % 17 == 13 then
39− 9.0 + (toFloat i)
40−
41− else if i == 101 then
42− 39.0 + (toFloat i)
43−
44− else if i == 102 then
45− 38.0 + (toFloat i)
46−
47− else if i == 103 then
48− 49.0 + (toFloat i)
49−
50− else if i == 104 then
51− 59.0 + (toFloat i)
52−
53− else if i == 105 then
54− 69.0 + (toFloat i)
55−
56− else if i == 106 then
57− 39.0 + (toFloat i)
58−
59− else if i == 107 then
60− 38.0 + (toFloat i)
61−
62− else if i == 108 then
63− 49.0 + (toFloat i)
64−
65− else if i == 109 then
66− 59.0 + (toFloat i)
67−
68− else if i == 110 then
69− 69.0 + (toFloat i)
70−
71− else if i == 111 then
72− 39.0 + (toFloat i)
73−
74− else if i == 115 then
75− 69.0 + (toFloat i)
76−
77− else if otherwise then
78− toFloat i
79−
80−
81−fewConditionFunction i =
82− if i <= 0 then
83− 30.0 + (toFloat i)
84−
85− else if i == 104 then
86− 59.0 + (toFloat i)
87−
88− else if i == 105 then
89− 69.0 + (toFloat i)
90−
91− else
92− toFloat i
93−
94−
95−tailRecSum intList =
96− List.foldr (\i sumSoFar -> sumSoFar + tailRecursiveIfFn i ) 0.0 intList
97−
98−
99−manyConditionalSum intList =
100− List.foldr (\i sumSoFar -> sumSoFar + manyConditionFunction i ) 0.0 intList
101−
102−
103−fewConditionalSum intList =
104− List.foldr (\i sumSoFar -> sumSoFar + fewConditionFunction i ) 0.0 intList
bench/src/LargeDictionary.elmdeleted−34
@@ -1,34 +0,0 @@
1−module LargeDictionary where
2−
3−
4−import Dict
5−import Random
6−import Signal
7−import Time
8−import Graphics.Element
9−
10−
11−maxSize = 10000000
12−
13−
14−randomGen =
15− Random.int (-1 * maxSize) (maxSize)
16−
17−
18−addNToDictWithSeed
19− : Int
20− -> Random.Seed
21− -> Dict.Dict Int Int
22− -> Dict.Dict Int Int
23−addNToDictWithSeed n seed accum =
24− case n of
25− 0 -> accum
26− _ ->
27− let
28− (nextToAdd, newSeed) = Random.generate randomGen seed
29− newAccum = Dict.insert nextToAdd nextToAdd accum
30− in addNToDictWithSeed (n-1) newSeed newAccum
31−
32−
33−addNToDictAndSum numToInsert =
34− addNToDictWithSeed numToInsert (Random.initialSeed 23) Dict.empty
bench/src/ListBench.elmdeleted−85
@@ -1,85 +0,0 @@
1−module ListBench where
2−
3−import Random
4−
5−
6−
7−randomList
8− : Random.Generator a
9− -> Int
10− -> Random.Seed
11− -> List a
12−randomList gen n initSeed =
13− let
14− f n (seed, accum) =
15− let
16− (nextToAdd, newSeed) = Random.generate gen seed
17− newAccum = nextToAdd :: accum
18− in (newSeed, newAccum)
19− in
20− snd <| List.foldl f (initSeed, []) [1 .. n]
21−
22−meanAndStddev
23− : ((Float -> (Float, Float) -> (Float, Float)) -> (Float, Float) -> List Float -> (Float, Float))
24− -> List Float
25− -> (Float, Float)
26−meanAndStddev foldFn ourList =
27− let
28− --ourList = addNToListWithSeed n (Random.initialSeed 23)
29− (theSum, sumSq) = foldFn (\x (sum, sumSq) -> (x + sum, (x^2) + sumSq) ) (0,0) ourList
30− in
31− (theSum, sqrt(theSum*theSum - sumSq))
32−
33−
34−foldrMeanStddev = meanAndStddev List.foldr
35−
36−
37−foldlMeanStddev = meanAndStddev List.foldl
38−
39−
40−customFoldrMeanStddev = meanAndStddev myFoldr
41−
42−
43−customFoldlMeanStddev = meanAndStddev myFoldl
44−
45−
46−updateNRandomIndices
47− : (Float -> Float)
48− -> List Int
49− -> List Float
50− -> List Float
51−updateNRandomIndices f indexList startList =
52− List.foldr
53− (\ i oldList -> updateN i f oldList)
54− startList indexList
55−
56−
57−
58−randomLookups : List Int -> List Float -> List (Maybe Float)
59−randomLookups indices ourList =
60− let
61− getNth i l =
62− case (i, l) of
63− (_, []) -> Nothing
64− (0, x :: _) -> Just x
65− (i, _ :: xs ) -> getNth i xs
66− in List.map (\i -> getNth i ourList) indices
67−
68−
69−myFoldl : (a -> b -> b) -> b -> List a -> b
70−myFoldl f init l =
71− case l of
72− [] -> init
73− (x :: xs) -> myFoldl f (f x init) xs
74−
75−
76−myFoldr : (a -> b -> b) -> b -> List a -> b
77−myFoldr f init l =
78− case l of
79− [] -> init
80− (x :: xs) -> f x (myFoldr f init xs)
81−
82−
83−updateN : Int -> (a -> a) -> List a -> List a
84−updateN n f list =
85− List.indexedMap (\index value -> if index == n then f value else value) list
bench/src/Main.elmnew file+34
@@ -0,0 +1,34 @@
1+module Main where
2+
3+import Graphics.Element exposing (leftAligned)
4+import Signal
5+import Task
6+import Text
7+
8+import Benchmark
9+import Realistic.Todo as Todo
10+
11+
12+-- COMPILER BENCHMARK
13+
14+compilerBenchmark : List Benchmark.Benchmark
15+compilerBenchmark =
16+ [ Todo.benchmark
17+ ]
18+
19+
20+-- DISPLAY THINGS
21+
22+main =
23+ Signal.map (leftAligned << Text.fromString) results.signal
24+
25+
26+results : Signal.Mailbox String
27+results =
28+ Signal.mailbox "Working..."
29+
30+
31+port benchResults : Task.Task x ()
32+port benchResults =
33+ Benchmark.run compilerBenchmark
34+ `Task.andThen` (Benchmark.statisticsToString >> Signal.send results.address)
bench/src/PatternMatchBench.elmdeleted−70
@@ -1,70 +0,0 @@
1−module PatternMatchBench where
2−
3−type NestedStructure =
4− Nest Float (NestedStructure)
5− | End Float
6−
7−
8−intToNest : Int -> NestedStructure
9−intToNest i =
10− let
11− helper i accum =
12− case (i % 20) of
13− 0 ->
14− accum
15−
16− _ ->
17− helper (i-1) <| Nest (toFloat <| i * i) accum
18− in
19− helper i (End <| toFloat i)
20−
21−deepMatchingFunction : NestedStructure -> Float
22−deepMatchingFunction struct =
23− case struct of
24− (Nest x1 (Nest x2 (Nest x3 (Nest x4 (Nest x5 (Nest x6 (Nest x7 (Nest x8 (Nest x9 (Nest x10 (Nest x11 (Nest x12 (Nest x13 (Nest x14 (Nest x15 (Nest x16 (Nest x17 (End x18 ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ->
25− x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18
26−
27− Nest x _ ->
28− x
29−
30− End x ->
31− x
32−
33−
34−wildcardMatchingFunction : NestedStructure -> Float
35−wildcardMatchingFunction struct =
36− case struct of
37− (Nest x (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (Nest _ (End y ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ->
38− x + y + x + y + x + y + x + y + x + y + x + y + x + y + x + y + x + y
39−
40− Nest x _ ->
41− x
42−
43− End x ->
44− x
45−
46−
47−shallowMatchingFunction : NestedStructure -> Float
48−shallowMatchingFunction struct =
49− case struct of
50− (Nest x1 (Nest x2 (Nest x3 (End x4) ) ) ) ->
51− x1 + x2 + x3 + x4 + x1 + x2 + x3 + x4 + x1 + x2 + x3 + x4 + x1 + x2 + x3 + x4 + x1 + x2
52−
53− Nest x _ ->
54− x
55−
56− End x ->
57− x
58−
59−sumStructures : (NestedStructure -> Float) -> List NestedStructure -> Float
60−sumStructures f inList =
61− List.foldr (\x sumSoFar -> sumSoFar + f x) 0.0 inList
62−
63−
64−deepMatchSum = sumStructures deepMatchingFunction
65−
66−
67−shallowMatchSum = sumStructures shallowMatchingFunction
68−
69−
70−wildcardMatchSum = sumStructures wildcardMatchingFunction
bench/src/TodoBench.elm → bench/src/Realistic/Todo.elmrenamed

The content is the same.

bench/src/RecordBench.elmdeleted−76
@@ -1,76 +0,0 @@
1−module RecordBench where
2−
3−type alias BigRecord =
4− { myLargeNamedField1 : Float
5− , myLargeNamedField2 : Float
6− , myLargeNamedField3 : Float
7− , myLargeNamedField4 : Float
8− , myLargeNamedField5 : Float
9− , myLargeNamedField6 : Float
10− , myLargeNamedField7 : Float
11− , myLargeNamedField8 : Float
12− , myLargeNamedField9 : Float
13− , myLargeNamedField10 : Float
14− , myLargeNamedField11 : Float
15− , myLargeNamedField12 : Float
16− , myLargeNamedField13 : Float
17− , myLargeNamedField14 : Float
18− , myLargeNamedField15 : Float
19− , myLargeNamedField16 : Float
20− , myLargeNamedField17 : Float
21− , myLargeNamedField18 : Float
22− , myLargeNamedField19 : Float
23− , myLargeNamedField20 : Float
24− }
25−
26−defaultRec =
27− BigRecord 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0
28− 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0
29−
30−getField i =
31− case (i % 20) of
32− 0 ->
33− defaultRec.myLargeNamedField20
34− 1 ->
35− defaultRec.myLargeNamedField1
36− 2 ->
37− defaultRec.myLargeNamedField2
38− 3 ->
39− defaultRec.myLargeNamedField3
40− 4 ->
41− defaultRec.myLargeNamedField4
42− 5 ->
43− defaultRec.myLargeNamedField5
44− 6 ->
45− defaultRec.myLargeNamedField6
46− 7 ->
47− defaultRec.myLargeNamedField7
48− 8 ->
49− defaultRec.myLargeNamedField8
50− 9 ->
51− defaultRec.myLargeNamedField9
52− 10 ->
53− defaultRec.myLargeNamedField10
54− 11 ->
55− defaultRec.myLargeNamedField11
56− 12 ->
57− defaultRec.myLargeNamedField12
58− 13 ->
59− defaultRec.myLargeNamedField13
60− 14 ->
61− defaultRec.myLargeNamedField14
62− 15 ->
63− defaultRec.myLargeNamedField15
64− 16 ->
65− defaultRec.myLargeNamedField16
66− 17 ->
67− defaultRec.myLargeNamedField17
68− 18 ->
69− defaultRec.myLargeNamedField18
70− 19 ->
71− defaultRec.myLargeNamedField19
72−
73−
74−sumRandomElems : List Int -> Float
75−sumRandomElems randomInts =
76− List.foldr (\i sumSoFar -> (getField i) + sumSoFar ) 0.0 randomInts
bench/src/SmallCtorBench.elmdeleted−76
@@ -1,76 +0,0 @@
1−module SmallCtorBench where
2−
3−type ManyCtors =
4− MyLongNamedCtor1 Float Float Float
5− | MyLongNamedCtor2 Float Float
6− | MyLongNamedCtor3 Float Float Float
7− | MyLongNamedCtor4 Float Float
8− | MyLongNamedCtor5 Float Float Float
9− | MyLongNamedCtor6 Float Float
10− | MyLongNamedCtor7 Float Float Float
11− | MyLongNamedCtor8 Float Float
12− | MyLongNamedCtor9 Float Float Float
13− | MyLongNamedCtor10 Float Float
14−
15−
16−getFieldSum someData =
17− case someData of
18− MyLongNamedCtor1 x y z ->
19− x + y + z
20−
21− MyLongNamedCtor3 x y z ->
22− x + y + z
23−
24− MyLongNamedCtor5 x y z ->
25− x + y + z
26−
27− MyLongNamedCtor7 x y z ->
28− x + y + z
29−
30− MyLongNamedCtor9 x y z ->
31− x + y + z
32−
33− MyLongNamedCtor10 x y ->
34− x + y
35−
36− MyLongNamedCtor8 x y ->
37− x + y
38−
39− MyLongNamedCtor6 x y ->
40− x + y
41−
42− MyLongNamedCtor4 x y ->
43− x + y
44−
45− MyLongNamedCtor2 x y ->
46− x + y
47−
48−
49−makeRandomData i =
50− case (i % 10) of
51− 0 ->
52− MyLongNamedCtor10 (toFloat i) (toFloat <| i*i)
53− 1 ->
54− MyLongNamedCtor1 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
55− 2 ->
56− MyLongNamedCtor2 (toFloat i) (toFloat <| i*i)
57− 3 ->
58− MyLongNamedCtor3 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
59− 4 ->
60− MyLongNamedCtor4 (toFloat i) (toFloat <| i*i)
61− 5 ->
62− MyLongNamedCtor5 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
63− 6 ->
64− MyLongNamedCtor6 (toFloat i) (toFloat <| i*i)
65− 7 ->
66− MyLongNamedCtor7 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
67− 8 ->
68− MyLongNamedCtor8 (toFloat i) (toFloat <| i*i)
69− 9 ->
70− MyLongNamedCtor9 (toFloat i) (toFloat <| i*i) (toFloat <| i*i*i)
71−
72−
73−
74−sumFieldsList : List ManyCtors -> Float
75−sumFieldsList dataList =
76− List.foldr (\val sumSoFar -> (getFieldSum val) + sumSoFar ) 0.0 dataList
bench/src/SmallRecordBench.elmdeleted−42
@@ -1,42 +0,0 @@
1−module SmallRecordBench where
2−
3−type alias SmallRecord =
4− { myLargeNamedField1 : Float
5− , myLargeNamedField2 : Float
6− , myLargeNamedField3 : Float
7− , myLargeNamedField4 : Float
8− , myLargeNamedField5 : Float
9− , myLargeNamedField6 : Float
10− , myLargeNamedField7 : Float
11− , myLargeNamedField8 : Float
12− , myLargeNamedField9 : Float
13− }
14−
15−defaultRec =
16− SmallRecord 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
17−
18−getField i =
19− case (i % 9) of
20− 1 ->
21− defaultRec.myLargeNamedField1
22− 2 ->
23− defaultRec.myLargeNamedField2
24− 3 ->
25− defaultRec.myLargeNamedField3
26− 4 ->
27− defaultRec.myLargeNamedField4
28− 5 ->
29− defaultRec.myLargeNamedField5
30− 6 ->
31− defaultRec.myLargeNamedField6
32− 7 ->
33− defaultRec.myLargeNamedField7
34− 8 ->
35− defaultRec.myLargeNamedField8
36− 0 ->
37− defaultRec.myLargeNamedField9
38−
39−
40−sumRandomElems : List Int -> Float
41−sumRandomElems randomInts =
42− List.foldr (\i sumSoFar -> (getField i) + sumSoFar ) 0.0 randomInts
bench/src/SmallTupleBench.elmdeleted−30
@@ -1,30 +0,0 @@
1−module SmallTupleBench where
2−
3−type alias SmallTuple =
4− ( Float
5− , Float
6− , Float
7− , Float
8− , Float
9− , Float
10− , Float
11− , Float
12− , Float
13− )
14−
15−defaultTuple =
16− (1.0, 2.0, 3.0)
17−
18−getField (x1, x2, x3) i =
19− case (i % 3) of
20− 1 ->
21− x1
22− 2 ->
23− x2
24− 0 ->
25− x3
26−
27−
28−sumRandomElems : List Int -> Float
29−sumRandomElems randomInts =
30− List.foldr (\i sumSoFar -> (getField defaultTuple i) + sumSoFar ) 0.0 randomInts
bench/src/TupleBench.elmdeleted−42
@@ -1,42 +0,0 @@
1−module TupleBench where
2−
3−type alias BigTuple =
4− ( Float
5− , Float
6− , Float
7− , Float
8− , Float
9− , Float
10− , Float
11− , Float
12− , Float
13− )
14−
15−defaultTuple =
16− (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
17−
18−getField (x1, x2, x3, x4, x5, x6, x7, x8, x9) i =
19− case (i % 9) of
20− 1 ->
21− x1
22− 2 ->
23− x2
24− 3 ->
25− x3
26− 4 ->
27− x4
28− 5 ->
29− x5
30− 6 ->
31− x6
32− 7 ->
33− x7
34− 8 ->
35− x8
36− 0 ->
37− x9
38−
39−
40−sumRandomElems : List Int -> Float
41−sumRandomElems randomInts =
42− List.foldr (\i sumSoFar -> (getField defaultTuple i) + sumSoFar ) 0.0 randomInts