on ff98144 help sign in
elk/bench/CompilerBenchmarks.elm
165 lines 5.9 kB history raw
1import Graphics.Element exposing (show)
2import Signal
3import Benchmark
4import Task exposing (Task, andThen)
5import Text
6import Array
7import Random
8import Dict
9import Time
11import LargeDictionary
12import ArrayBench
13import ListBench
15import RecordBench
16import SmallRecordBench
17import TupleBench
18import SmallTupleBench
19import CtorBench
20import SmallCtorBench
21import PatternMatchBench
22import IfBench
23import DictBench
25import AnimateBench
26import TodoBench
28{-| Compile this with --output=Benchmarks.html to generate
29 a webpage, which runs the benchmarks and shows the results.
30-}
33mySuite =
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
38 , Benchmark.bench1 "Access 9-field tuple 200 times: " TupleBench.sumRandomElems indices200
39 , Benchmark.bench1 "Access 3-field tuple 200 times: " SmallTupleBench.sumRandomElems indices200
41 , Benchmark.bench1 "Access 20-constructor Type 200 times: " CtorBench.sumFieldsList ctorData200
42 , Benchmark.bench1 "Access 10-constructor Type 200 times: " SmallCtorBench.sumFieldsList smallCtorData200
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
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
52 , Benchmark.bench1 "Make and sum dict, 10000 elems: " LargeDictionary.addNToDictAndSum 10000
53 , Benchmark.bench1 "Make and sum dict, 50 elems: " LargeDictionary.addNToDictAndSum 50
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
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
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
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]) )
75 , Benchmark.bench1 "30s simulated animation @ 30fps: " AnimateBench.runAnimation timeSteps30s
76 , Benchmark.bench1 "TodoMVC: approx. 330 simulated actions " TodoBench.evalActions TodoBench.testActions
77 ]
80--Display of results:
82--Mailbox updated with benchmark run progress
83results : Signal.Mailbox String
84results =
85 Signal.mailbox "Benchmark loading"
88--The actual task which runs the benchmarks
89port benchResults : (Task Benchmark.Never ())
90port benchResults =
91 Benchmark.runWithProgress (Just results) mySuite
92 `andThen` \_ -> Task.sleep 0
95--Our main page:
96main =
97 Signal.map (Graphics.Element.leftAligned << Text.fromString) results.signal
101-- Random generation and structures
103--Maximum size for random numbers
104maxSize = 1000000
107--Random generator for floating point numbers
108floatGen =
109 Random.float (-1 * maxSize) (maxSize)
112--Generate random indices for lists out of 500 elements
113indexGen =
114 Random.int (0) (499)
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
121--seed for our index generation
122indexSeed =
123 Random.initialSeed 56
126--Seed for our float generation
127seed =
128 Random.initialSeed 23
131--Pseudo-random array of 500 floating point numbers
132array500 =
133 (ArrayBench.randomArray floatGen 500 seed)
136--Pseudo-random dictionary, indexed 0 .. 500, of 500 floating point numbers
137dict500 =
138 (DictBench.randomDict floatGen 500 seed)
142--Same contents as array500, but in list form
143list500 =
144 (ListBench.randomList floatGen 500 seed)
147--Pseudo random list of 200 indices between 0 and 499
148indices200 =
149 (ListBench.randomList indexGen 200 indexSeed)
152--List of timesteps simulating 30 seconds of animation at 30fps
153timeSteps30s =
154 List.map (\x -> (1.0 / 30.0) * (toFloat x * Time.second) ) [1 .. 900]
156ctorData200 =
157 List.map CtorBench.makeRandomData indices200
160smallCtorData200 =
161 List.map SmallCtorBench.makeRandomData indices200
164nestedData200 =
165 List.map PatternMatchBench.intToNest indices200