-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FunctionComposition.elm
40 lines (29 loc) · 1.1 KB
/
FunctionComposition.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
module WhatIsFaster.FunctionComposition exposing (main)
{-| This benchmark aims to showcase the difference between functions composed
over anonymous lambdas that call the functions themselves.
We notice that the function composition adds quite a lot of overhead,
as the lambda function is 3 times faster, and the difference seems to increase as you compose more functions.
Related benchmarks: ImprovingPerformance.ElmCore.ListAll
-}
import Benchmark exposing (Benchmark, describe)
import Benchmark.Runner exposing (BenchmarkProgram, program)
suite : Benchmark
suite =
describe "Function composition"
[ Benchmark.compare "2 functions"
">>"
(\() -> (increment >> increment) 10)
"lambda"
(\() -> (\n -> increment (increment n)) 10)
, Benchmark.compare "3 functions"
">>"
(\() -> (increment >> increment >> increment) 10)
"lambda"
(\() -> (\n -> increment (increment (increment n))) 10)
]
main : BenchmarkProgram
main =
program suite
increment : number -> number
increment a =
a + 1