-
Notifications
You must be signed in to change notification settings - Fork 2
/
Benchmark.elm
80 lines (62 loc) · 2.62 KB
/
Benchmark.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module Benchmark
( logic
, render
, renderStatic
, run
, Benchmark
) where
{-|
Simple Benchmarking library
# Basic Benchmarks
@docs logic, render, renderStatic
# Run the benchmark
@docs run
-}
import Benchmark.Types as T
import Benchmark.Runner as R
-- Bindings from other files for a cleaner export
type Benchmark = T.Benchmark
{-| Create a logic benchmark, running a function on many different inputs.
You provide a name, a function, and a list of input values. After the benchmark
suite runs, you will see results for each input all labeled with the given name.
logic "Date Parsing" parseDate [ "1/2/1990", "1 Feb 1990", "February 1, 1990" ]
-}
logic : String -> (input -> output) -> [input] -> Benchmark
logic name function inputs =
let noSetup f input = \_ -> let muted a = always () (f a)
in \_ -> muted input
in T.Logic name <| map (noSetup function) inputs
{-| Create a rendering benchmark, rendering a sequence of states. You provide a
name, a rendering function, and a sequence of states. Running this benchmark
measures the whole rendering pipeline.
render "Profile" userProfile [ { user=123, friends=0 }
, { user=123, friends=1 }
, { user=123, friends=2 }
, { user=123, friends=1 }
]
The sequence of states really is a *sequence*. They are run in order, so you can
see how well Elm's diffing engine does given the particular sequence you give it.
It may help to record a sequence of states directly from your project. Better to
use real data instead of making it up!
-}
render : String -> (input -> Element) -> [input] -> Benchmark
render name function inputs =
let noSetup f input = \_ _-> f input
in T.Render name <| map (noSetup function) inputs
{-| Just get the cost of rendering from scratch. This does not get any of
the benefits of diffing to speed things up, so it is mainly useful for
assessing page load time.
renderStatic "Markdown rendering" markdownBlock
-}
renderStatic : String -> Element -> Benchmark
renderStatic name element = render name (\_ -> element) [()]
{-| For each benchmark, run it 10 times in a row and average the times. If the
benchmark needs to render something, it goes to screen. Once the benchmarks are
completed, the screen will change to display them as a line graph
benchmarks = [ render "Blur image" blurPonyPNG [1..50]
, logic "Compute determinant" [m1, m2, m3, m4]
]
main = run benchmarks
-}
run : [Benchmark] -> Signal Element
run = R.run