git.iko.soy/typeable/elm-ui
on master help sign in
micro-benchmarks
commit59d31e11a0988456653aab5a79ce74e42ab2ad9f authorMatthew Griffith <mdg.griffith@gmail.com> dateMon 1 Jul 2019, 20:44 (7 years ago) parent1e7336e
2 files changed+127
benchmarks/micro/Suite.elm+98 benchmarks/micro/elm.json+29
benchmarks/micro/Suite.elmnew file+98
@@ -0,0 +1,98 @@
1+module Suite exposing (main)
2+
3+import Benchmark exposing (Benchmark)
4+import Benchmark.Runner exposing (BenchmarkProgram, program)
5+import Dict
6+import Json.Encode
7+import Set
8+
9+
10+dict : Benchmark
11+dict =
12+ let
13+ dest =
14+ Dict.singleton "a" 1
15+ in
16+ Benchmark.describe "dictionary"
17+ [ Benchmark.benchmark "get" (\_ -> Dict.get "a" dest)
18+ , Benchmark.benchmark "insert" (\_ -> Dict.insert "b" 2 dest)
19+ ]
20+
21+
22+main : BenchmarkProgram
23+main =
24+ program <|
25+ Benchmark.describe "sample"
26+ [ dict
27+ , deduplications
28+ ]
29+
30+
31+deduplications =
32+ Benchmark.describe "deduplications"
33+ [ Benchmark.benchmark "fold - dedup, String concat"
34+ (\_ ->
35+ String.join ":" (foldDedup largeList)
36+ )
37+ , Benchmark.benchmark "fold - dedup"
38+ (\_ ->
39+ foldDedup largeList
40+ )
41+ , Benchmark.benchmark "fold - dedup - Int"
42+ (\_ ->
43+ foldDedup largeListInt
44+ )
45+ , Benchmark.benchmark "Json encode"
46+ (\_ ->
47+ Json.Encode.object largeListJson
48+ )
49+ ]
50+
51+
52+foldDedup list =
53+ let
54+ dedup ( name, val ) ( cache, ls ) =
55+ if Set.member name cache then
56+ ( cache, ls )
57+
58+ else
59+ ( Set.insert name cache, val :: ls )
60+ in
61+ List.foldl dedup ( Set.empty, [] ) list
62+ |> Tuple.second
63+
64+
65+largeListInt =
66+ List.range 1 10000
67+ |> List.map
68+ (\i ->
69+ let
70+ wrappingI =
71+ modBy 50 i
72+ in
73+ ( wrappingI, "elem-" ++ String.fromInt wrappingI )
74+ )
75+
76+
77+largeList =
78+ List.range 1 10000
79+ |> List.map
80+ (\i ->
81+ let
82+ wrappingI =
83+ modBy 50 i
84+ in
85+ ( "elem-" ++ String.fromInt wrappingI, "elem-" ++ String.fromInt wrappingI )
86+ )
87+
88+
89+largeListJson =
90+ List.range 1 10000
91+ |> List.map
92+ (\i ->
93+ let
94+ wrappingI =
95+ modBy 50 i
96+ in
97+ ( "elem-" ++ String.fromInt wrappingI, Json.Encode.string ("elem-" ++ String.fromInt wrappingI) )
98+ )
benchmarks/micro/elm.jsonnew file+29
@@ -0,0 +1,29 @@
1+{
2+ "type": "application",
3+ "source-directories": [
4+ "."
5+ ],
6+ "elm-version": "0.19.0",
7+ "dependencies": {
8+ "direct": {
9+ "elm/browser": "1.0.1",
10+ "elm/core": "1.0.2",
11+ "elm/html": "1.0.0",
12+ "elm/json": "1.1.3",
13+ "elm/time": "1.0.0",
14+ "elm-explorations/benchmark": "1.0.1"
15+ },
16+ "indirect": {
17+ "BrianHicks/elm-trend": "2.1.2",
18+ "Skinney/murmur3": "2.0.8",
19+ "elm/regex": "1.0.0",
20+ "elm/url": "1.0.0",
21+ "elm/virtual-dom": "1.0.2",
22+ "mdgriffith/style-elements": "5.0.1"
23+ }
24+ },
25+ "test-dependencies": {
26+ "direct": {},
27+ "indirect": {}
28+ }
29+}