This repository has been archived by the owner on Sep 17, 2020. It is now read-only.
forked from robinheghan/elm-array-exploration
/
Main.elm
46 lines (39 loc) · 1.62 KB
/
Main.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Main exposing (main)
import Benchmark.Runner exposing (BenchmarkProgram, program)
import Benchmark exposing (Benchmark)
import Array.Hamt as Array
import Native.JsArray
main : BenchmarkProgram
main =
program <| suite
suite : Benchmark
suite =
let
hamt =
Array.fromList [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
( arr, _ ) =
Native.JsArray.initializeFromList 99 [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
fromArray arr =
Native.JsArray.foldr (\item acc -> item :: acc) [] arr
in
Benchmark.describe "Literal representations"
[ Benchmark.compare "List Sum"
"Literal"
(\_ -> List.foldl (\a b -> a + b) 0 [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ])
"Runtime conversion"
(\_ -> List.foldl (\a b -> a + b) 0 (fromArray arr))
, Benchmark.compare "Literal Sum"
"Array"
-- For an accurate comparison, edit the compiled index.html
-- replace 'hamt' with '{ctor:'Array',_0:9,_1:5,_2:[],_3:[1,2,3,4,5,6,7,8,9]}'
(\_ -> Array.foldl (\a b -> a + b) 0 hamt)
"List"
(\_ -> List.foldl (\a b -> a + b) 0 [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ])
, Benchmark.compare "Runtime Sum"
"Array"
-- For an accurate comparison, edit the compiled index.html
-- replace 'hamt' with '{ctor:'Array',_0:9,_1:5,_2:[],_3:[1,2,3,4,5,6,7,8,9]}'
(\_ -> Array.foldl (\a b -> a + b) 0 hamt)
"List"
(\_ -> List.foldl (\a b -> a + b) 0 (fromArray arr))
]