on master help sign in
Added If benchmarks
6384b3cjmite
bench/CompilerBenchmarks.elm+4
@@ -18,6 +18,7 @@ import SmallTupleBench
18import CtorBench
18import CtorBench
19import SmallCtorBench
19import SmallCtorBench
20import PatternMatchBench
20import PatternMatchBench
21+import IfBench
21
22
22{-| Compile this with --output=Benchmarks.html to generate
23{-| Compile this with --output=Benchmarks.html to generate
23 a webpage, which runs the benchmarks and shows the results.
24 a webpage, which runs the benchmarks and shows the results.
@@ -35,6 +36,9 @@ mySuite =
35 , Benchmark.bench1 "Access 20-constructor Type 200 times: " CtorBench.sumFieldsList ctorData200
36 , Benchmark.bench1 "Access 20-constructor Type 200 times: " CtorBench.sumFieldsList ctorData200
36 , Benchmark.bench1 "Access 10-constructor Type 200 times: " SmallCtorBench.sumFieldsList smallCtorData200
37 , Benchmark.bench1 "Access 10-constructor Type 200 times: " SmallCtorBench.sumFieldsList smallCtorData200
37
38
39+ , Benchmark.bench1 "Tail-recursive if function, called 200 times: " IfBench.tailRecSum indices200
40+ , Benchmark.bench1 "Tail-recursive if function, called 200 times: " IfBench.manyConditionalSum indices200
41+
38 , Benchmark.bench1 "Pattern match 18-levels deep, use all values, 200 times " PatternMatchBench.deepMatchSum nestedData200
42 , 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
43 , 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
44 , Benchmark.bench1 "Pattern match 4-levels deep, use all values, 200 times " PatternMatchBench.shallowMatchSum nestedData200
bench/src/IfBench.elmnew file+51
@@ -0,0 +1,51 @@
1+module IfBench where
2+
3+tailRecursiveIfFn : Int -> Float
4+tailRecursiveIfFn i =
5+ if
6+ | i < 0 ->
7+ 10.0
8+ | i == 0 ->
9+ 20.0
10+ | i > 0 && i < 10 ->
11+ 30.0
12+ | otherwise ->
13+ tailRecursiveIfFn (i - (1 + (i % 5 ) ) )
14+
15+
16+manyConditionFunction i =
17+ if
18+ | i <= 0 ->
19+ 30.0 + (toFloat i)
20+ | i > 100 && (i * i) % 20 == 7 ->
21+ 24.3 + (toFloat i)
22+ | i > 100 && (i % 3 == 1) ->
23+ 3.33 + (toFloat i)
24+ | (i == 152) ->
25+ 29.0 + (toFloat i)
26+ | (i + (i*i) > 200 && (i + (i*i) < 300)) ->
27+ 32.9 + (toFloat i)
28+ | i == 99 ->
29+ 93.0 + (toFloat i)
30+ | (i*i % 17 == 13 ) ->
31+ 9.0 + (toFloat i)
32+ | (i == 101) ->
33+ 39.0 + (toFloat i)
34+ | (i == 102) ->
35+ 38.0 + (toFloat i)
36+ | (i == 103) ->
37+ 49.0 + (toFloat i)
38+ | (i == 104) ->
39+ 59.0 + (toFloat i)
40+ | (i == 105) ->
41+ 69.0 + (toFloat i)
42+ | otherwise ->
43+ toFloat i
44+
45+
46+tailRecSum intList =
47+ List.foldr (\i sumSoFar -> sumSoFar + tailRecursiveIfFn i ) 0.0 intList
48+
49+manyConditionalSum intList =
50+ List.foldr (\i sumSoFar -> sumSoFar + manyConditionFunction i ) 0.0 intList
51+