mirror of
https://github.com/mdgriffith/elm-ui.git
synced 2024-11-22 11:52:09 +03:00
more micro benchmarks, because why not
This commit is contained in:
parent
cc9b2aca20
commit
13364449da
@ -3,6 +3,13 @@ module Suite exposing (main)
|
||||
import Benchmark exposing (Benchmark)
|
||||
import Benchmark.Runner exposing (BenchmarkProgram, program)
|
||||
import Dict
|
||||
import Element exposing (..)
|
||||
import Element.Background as Background
|
||||
import Element.Font as Font
|
||||
import Html
|
||||
import Html.Attributes
|
||||
import Internal.Flag as Flag
|
||||
import Internal.Model as Internal
|
||||
import Json.Encode
|
||||
import Set
|
||||
|
||||
@ -23,11 +30,150 @@ main : BenchmarkProgram
|
||||
main =
|
||||
program <|
|
||||
Benchmark.describe "sample"
|
||||
[ dict
|
||||
, deduplications
|
||||
[ --dict
|
||||
-- , deduplications
|
||||
-- renderPipeline
|
||||
gatheringAttributes
|
||||
|
||||
-- flagOperations
|
||||
]
|
||||
|
||||
|
||||
flagOperations =
|
||||
Benchmark.describe "Flag Operations"
|
||||
[ Benchmark.benchmark "check if present" <|
|
||||
\_ ->
|
||||
Flag.present Flag.height Flag.none
|
||||
, Benchmark.benchmark "add to flagt" <|
|
||||
\_ ->
|
||||
Flag.add Flag.height Flag.none
|
||||
]
|
||||
|
||||
|
||||
gatheringAttributes =
|
||||
Benchmark.describe "Gathering Attributes"
|
||||
[ Benchmark.benchmark "existing - gatherAttrRecursive" <|
|
||||
\_ ->
|
||||
Internal.gatherAttrRecursive
|
||||
(Internal.contextClasses Internal.AsEl)
|
||||
Internal.Generic
|
||||
Flag.none
|
||||
Internal.Untransformed
|
||||
[]
|
||||
[]
|
||||
Internal.NoNearbyChildren
|
||||
[ Element.width Element.shrink
|
||||
, Element.height Element.shrink
|
||||
]
|
||||
, Benchmark.benchmark "Simple list filterMap" <|
|
||||
\_ ->
|
||||
List.filterMap
|
||||
identity
|
||||
[ Just "thing"
|
||||
, Just "other width"
|
||||
]
|
||||
, Benchmark.benchmark "Simple list map" <|
|
||||
\_ ->
|
||||
List.map
|
||||
identity
|
||||
[ Just "thing"
|
||||
, Just "other width"
|
||||
]
|
||||
, Benchmark.benchmark "Foldl base speed" <|
|
||||
\_ ->
|
||||
List.foldl
|
||||
(::)
|
||||
[ Just "thing"
|
||||
, Just "other width"
|
||||
]
|
||||
, Benchmark.benchmark "Recursive" <|
|
||||
\_ ->
|
||||
recurse
|
||||
(::)
|
||||
[ Just "thing"
|
||||
, Just "other width"
|
||||
]
|
||||
, Benchmark.benchmark "foldl - new record each iteration" <|
|
||||
\_ ->
|
||||
List.foldl flipFoldl
|
||||
{ attributes = "class"
|
||||
, styles = []
|
||||
, node = "Node"
|
||||
, children = Nothing
|
||||
, has = Flag.none
|
||||
}
|
||||
-- we reverse first because we have to for the attr api.
|
||||
(List.reverse
|
||||
[ Just "thing"
|
||||
, Just "other width"
|
||||
]
|
||||
)
|
||||
, Benchmark.benchmark "foldl - update" <|
|
||||
\_ ->
|
||||
List.foldl flipFoldlUpdate
|
||||
{ attributes = "class"
|
||||
, styles = []
|
||||
, node = "Node"
|
||||
, children = Nothing
|
||||
, has = Flag.none
|
||||
}
|
||||
-- we reverse first because we have to for the attr api.
|
||||
(List.reverse
|
||||
[ Just "thing"
|
||||
, Just "other width"
|
||||
]
|
||||
)
|
||||
, Benchmark.benchmark "String Concatenation" <|
|
||||
\_ ->
|
||||
"This"
|
||||
++ "this"
|
||||
++ "this"
|
||||
++ "this"
|
||||
++ "this"
|
||||
++ "this"
|
||||
++ "this"
|
||||
++ "this"
|
||||
, Benchmark.benchmark "List String Concatenation" <|
|
||||
\_ ->
|
||||
String.concat
|
||||
[ "This"
|
||||
, "this"
|
||||
, "this"
|
||||
, "this"
|
||||
, "this"
|
||||
, "this"
|
||||
, "this"
|
||||
, "this"
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
flipFoldl result found =
|
||||
{ attributes = "class" ++ found.attributes
|
||||
, styles = Just 1 :: found.styles
|
||||
, node = found.node
|
||||
, children = Nothing
|
||||
, has = Flag.add Flag.height found.has
|
||||
}
|
||||
|
||||
|
||||
flipFoldlUpdate result found =
|
||||
{ found
|
||||
| attributes = "class" ++ found.attributes
|
||||
, styles = Just 1 :: found.styles
|
||||
, has = Flag.add Flag.height found.has
|
||||
}
|
||||
|
||||
|
||||
recurse fn ls =
|
||||
case ls of
|
||||
[] ->
|
||||
[]
|
||||
|
||||
fst :: remain ->
|
||||
fn fst (recurse fn remain)
|
||||
|
||||
|
||||
deduplications =
|
||||
Benchmark.describe "deduplications"
|
||||
[ Benchmark.benchmark "fold - dedup, String concat"
|
||||
@ -96,3 +242,89 @@ largeListJson =
|
||||
in
|
||||
( "elem-" ++ String.fromInt wrappingI, Json.Encode.string ("elem-" ++ String.fromInt wrappingI) )
|
||||
)
|
||||
|
||||
|
||||
renderPipeline =
|
||||
[ Benchmark.benchmark "build 2000 elements"
|
||||
(\_ ->
|
||||
elements 0 twoThousand
|
||||
)
|
||||
, Benchmark.benchmark "build 2000 html"
|
||||
(\_ ->
|
||||
html 0 twoThousand
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
twoThousand =
|
||||
List.range 0 2000
|
||||
|
||||
|
||||
elements i count =
|
||||
Element.layout []
|
||||
(Element.column [ spacing 8, centerX ]
|
||||
(List.map (viewEl i) count)
|
||||
)
|
||||
|
||||
|
||||
viewEl selectedIndex index =
|
||||
el
|
||||
[ Background.color
|
||||
(if selectedIndex == index then
|
||||
pink
|
||||
|
||||
else
|
||||
white
|
||||
)
|
||||
, Font.color
|
||||
(if selectedIndex /= index then
|
||||
pink
|
||||
|
||||
else
|
||||
white
|
||||
)
|
||||
, padding 24
|
||||
, width (px 500)
|
||||
, height (px 70)
|
||||
]
|
||||
(if selectedIndex == index then
|
||||
text "selected"
|
||||
|
||||
else
|
||||
text "Hello!"
|
||||
)
|
||||
|
||||
|
||||
white =
|
||||
rgb 1 1 1
|
||||
|
||||
|
||||
pink =
|
||||
rgb255 240 0 245
|
||||
|
||||
|
||||
html i count =
|
||||
Html.div []
|
||||
[ Html.div []
|
||||
(List.map (viewHtmlElement i) count)
|
||||
]
|
||||
|
||||
|
||||
viewHtmlElement selectedIndex index =
|
||||
Html.div
|
||||
[ Html.Attributes.class
|
||||
(if selectedIndex == index then
|
||||
"white"
|
||||
|
||||
else
|
||||
"pink"
|
||||
)
|
||||
]
|
||||
[ Html.div []
|
||||
[ if selectedIndex == index then
|
||||
Html.text "selected"
|
||||
|
||||
else
|
||||
Html.text "Hello!"
|
||||
]
|
||||
]
|
||||
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"."
|
||||
".",
|
||||
"../../src"
|
||||
],
|
||||
"elm-version": "0.19.0",
|
||||
"dependencies": {
|
||||
@ -11,6 +12,7 @@
|
||||
"elm/html": "1.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm/time": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2",
|
||||
"elm-explorations/benchmark": "1.0.1"
|
||||
},
|
||||
"indirect": {
|
||||
@ -18,7 +20,6 @@
|
||||
"Skinney/murmur3": "2.0.8",
|
||||
"elm/regex": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2",
|
||||
"mdgriffith/style-elements": "5.0.1"
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user