on 267f708 help sign in
elk/bench/src/Syntax/Records15.elm
109 lines 1.6 kB history raw
1module Syntax.Records15 (benchmark) where
3import Benchmark exposing (Benchmark, test, suite)
4import String
7benchmark : Benchmark.Benchmark
8benchmark =
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 ]
25-- RECORDS WITH 2 FIELDS
27record2 =
28 { x = 3
29 , y = 4
30 }
33update1of2 r _ =
34 { r | x <- r.x + 42 }
37update2of2 r _ =
38 { r
39 | x <- r.x + 1
40 , y <- r.y + 1
41 }
44new2of2 r _ =
45 { x = r.x + 1
46 , y = r.y + 1
47 }
50access2of2 r _ =
51 r.x + r.y
54-- RECORDS WITH 5 FIELDS
56record5 =
57 { product = "iPhone 6s"
58 , storage = 16
59 , weight = 143
60 , ppi = 326
61 , chip = "A9"
62 }
65update3of5 r _ =
66 { r
67 | product <- "iPhone 6s Plus"
68 , weight <- 192
69 , ppi <- 401
70 }
73update5of5 r _ =
74 { r
75 | product <- "iPhone 6"
76 , storage <- r.storage
77 , weight <- 129
78 , ppi <- r.ppi
79 , chip <- "A8"
80 }
83new5of5 r _ =
84 { product = "iPhone 6"
85 , storage = r.storage
86 , weight = 129
87 , ppi = r.ppi
88 , chip = "A8"
89 }
92-- RECORDS WITH 10 FIELDS
94record10 =
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 }
108access4of10 r _ =
109 r.a + r.b + r.c + r.d