on master help sign in
Add some benchmarking for record updates and accesses
8e22ac9Evan Czaplicki
bench/src/Main.elm+3−1
@@ -5,6 +5,7 @@ import Signal
5import Task
5import Task
6
6
7import Benchmark
7import Benchmark
8+import Syntax.Records as Records
8import Realistic.Todo as Todo
9import Realistic.Todo as Todo
9
10
10
11
@@ -13,7 +14,8 @@ import Realistic.Todo as Todo
13compilerBenchmark : Benchmark.Benchmark
14compilerBenchmark : Benchmark.Benchmark
14compilerBenchmark =
15compilerBenchmark =
15 Benchmark.suite "generated code"
16 Benchmark.suite "generated code"
17+ [ Records.benchmark
16− [ Todo.benchmark
18+ , Todo.benchmark
17 ]
19 ]
18
20
19
21
bench/src/Syntax/Records.elmnew file+109
@@ -0,0 +1,109 @@
1+module Syntax.Records (benchmark) where
2+
3+import Benchmark exposing (Benchmark, test, suite)
4+import String
5+
6+
7+benchmark : Benchmark.Benchmark
8+benchmark =
9+ suite "records"
10+ [ suite "update"
11+ [ test "1 of 2 fields" (update1of2 record2)
12+ , test "2 of 2 fields" (update2of2 record2)
13+ , test "2 of 2 new" (new2of2 record2)
14+ , test "3 of 5 fields" (update3of5 record5)
15+ , test "5 of 5 fields" (update5of5 record5)
16+ , test "5 of 5 new" (new5of5 record5)
17+ ]
18+ , suite "access"
19+ [ test "2 of 2" (access2of2 record2)
20+ , test "4 of 10" (access4of10 record10)
21+ ]
22+ ]
23+
24+
25+-- RECORDS WITH 2 FIELDS
26+
27+record2 =
28+ { x = 3
29+ , y = 4
30+ }
31+
32+
33+update1of2 r _ =
34+ { r | x = r.x + 42 }
35+
36+
37+update2of2 r _ =
38+ { r
39+ | x = r.x + 1
40+ , y = r.y + 1
41+ }
42+
43+
44+new2of2 r _ =
45+ { x = r.x + 1
46+ , y = r.y + 1
47+ }
48+
49+
50+access2of2 r _ =
51+ r.x + r.y
52+
53+
54+-- RECORDS WITH 5 FIELDS
55+
56+record5 =
57+ { product = "iPhone 6s"
58+ , storage = 16
59+ , weight = 143
60+ , ppi = 326
61+ , chip = "A9"
62+ }
63+
64+
65+update3of5 r _ =
66+ { r
67+ | product = "iPhone 6s Plus"
68+ , weight = 192
69+ , ppi = 401
70+ }
71+
72+
73+update5of5 r _ =
74+ { r
75+ | product = "iPhone 6"
76+ , storage = r.storage
77+ , weight = 129
78+ , ppi = r.ppi
79+ , chip = "A8"
80+ }
81+
82+
83+new5of5 r _ =
84+ { product = "iPhone 6"
85+ , storage = r.storage
86+ , weight = 129
87+ , ppi = r.ppi
88+ , chip = "A8"
89+ }
90+
91+
92+-- RECORDS WITH 10 FIELDS
93+
94+record10 =
95+ { a = 1
96+ , b = 2
97+ , c = 3
98+ , d = 4
99+ , e = True
100+ , f = 'a'
101+ , g = "abc"
102+ , h = record2
103+ , i = record5
104+ , j = [1,2,3]
105+ }
106+
107+
108+access4of10 r _ =
109+ r.a + r.b + r.c + r.d