on master help sign in
Added pattern match benchmarks
4cb3024jmite
bench/CompilerBenchmarks.elm+12−1
@@ -17,6 +17,7 @@ import TupleBench
17import SmallTupleBench
17import SmallTupleBench
18import CtorBench
18import CtorBench
19import SmallCtorBench
19import SmallCtorBench
20+import PatternMatchBench
20
21
21{-| Compile this with --output=Benchmarks.html to generate
22{-| Compile this with --output=Benchmarks.html to generate
22 a webpage, which runs the benchmarks and shows the results.
23 a webpage, which runs the benchmarks and shows the results.
@@ -27,11 +28,17 @@ mySuite =
27 Benchmark.Suite "My Suite"
28 Benchmark.Suite "My Suite"
28 [ Benchmark.bench1 "Access 20-field record 200 times: " RecordBench.sumRandomElems indices200
29 [ Benchmark.bench1 "Access 20-field record 200 times: " RecordBench.sumRandomElems indices200
29 , Benchmark.bench1 "Access 9-field record 200 times: " SmallRecordBench.sumRandomElems indices200
30 , Benchmark.bench1 "Access 9-field record 200 times: " SmallRecordBench.sumRandomElems indices200
31+
30 , Benchmark.bench1 "Access 9-field tuple 200 times: " TupleBench.sumRandomElems indices200
32 , Benchmark.bench1 "Access 9-field tuple 200 times: " TupleBench.sumRandomElems indices200
31 , Benchmark.bench1 "Access 3-field tuple 200 times: " SmallTupleBench.sumRandomElems indices200
33 , Benchmark.bench1 "Access 3-field tuple 200 times: " SmallTupleBench.sumRandomElems indices200
34+
32 , Benchmark.bench1 "Access 20-constructor Type 200 times: " CtorBench.sumFieldsList ctorData200
35 , Benchmark.bench1 "Access 20-constructor Type 200 times: " CtorBench.sumFieldsList ctorData200
33 , Benchmark.bench1 "Access 10-constructor Type 200 times: " SmallCtorBench.sumFieldsList smallCtorData200
36 , Benchmark.bench1 "Access 10-constructor Type 200 times: " SmallCtorBench.sumFieldsList smallCtorData200
34
37
38+ , Benchmark.bench1 "Pattern match 18-levels deep, use all values, 200 times " PatternMatchBench.deepMatchSum nestedData200
39+ , Benchmark.bench1 "Pattern match 18-levels deep, 16 wildcards, 200 times " PatternMatchBench.wildcardMatchSum nestedData200
40+ , Benchmark.bench1 "Pattern match 4-levels deep, use all values, 200 times " PatternMatchBench.shallowMatchSum nestedData200
41+
35 , Benchmark.bench1 "Make and sum dict, 10000 elems: " LargeDictionary.addNToDictAndSum 10000
42 , Benchmark.bench1 "Make and sum dict, 10000 elems: " LargeDictionary.addNToDictAndSum 10000
36 , Benchmark.bench1 "Make and sum dict, 50 elems: " LargeDictionary.addNToDictAndSum 50
43 , Benchmark.bench1 "Make and sum dict, 50 elems: " LargeDictionary.addNToDictAndSum 50
37
44
@@ -129,4 +136,8 @@ ctorData200 =
129
136
130
137
131smallCtorData200 =
138smallCtorData200 =
132− List.map SmallCtorBench.makeRandomData indices200
139+ List.map SmallCtorBench.makeRandomData indices200
140+
141+
142+nestedData200 =
143+ List.map PatternMatchBench.intToNest indices200
bench/src/PatternMatchBench.elmnew file+70
@@ -0,0 +1,70 @@
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