@@ -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