mirror of
https://github.com/mdgriffith/elm-ui.git
synced 2024-10-27 02:11:31 +03:00
micro-benchmarks
This commit is contained in:
parent
1e7336e702
commit
59d31e11a0
98
benchmarks/micro/Suite.elm
Normal file
98
benchmarks/micro/Suite.elm
Normal file
@ -0,0 +1,98 @@
|
||||
module Suite exposing (main)
|
||||
|
||||
import Benchmark exposing (Benchmark)
|
||||
import Benchmark.Runner exposing (BenchmarkProgram, program)
|
||||
import Dict
|
||||
import Json.Encode
|
||||
import Set
|
||||
|
||||
|
||||
dict : Benchmark
|
||||
dict =
|
||||
let
|
||||
dest =
|
||||
Dict.singleton "a" 1
|
||||
in
|
||||
Benchmark.describe "dictionary"
|
||||
[ Benchmark.benchmark "get" (\_ -> Dict.get "a" dest)
|
||||
, Benchmark.benchmark "insert" (\_ -> Dict.insert "b" 2 dest)
|
||||
]
|
||||
|
||||
|
||||
main : BenchmarkProgram
|
||||
main =
|
||||
program <|
|
||||
Benchmark.describe "sample"
|
||||
[ dict
|
||||
, deduplications
|
||||
]
|
||||
|
||||
|
||||
deduplications =
|
||||
Benchmark.describe "deduplications"
|
||||
[ Benchmark.benchmark "fold - dedup, String concat"
|
||||
(\_ ->
|
||||
String.join ":" (foldDedup largeList)
|
||||
)
|
||||
, Benchmark.benchmark "fold - dedup"
|
||||
(\_ ->
|
||||
foldDedup largeList
|
||||
)
|
||||
, Benchmark.benchmark "fold - dedup - Int"
|
||||
(\_ ->
|
||||
foldDedup largeListInt
|
||||
)
|
||||
, Benchmark.benchmark "Json encode"
|
||||
(\_ ->
|
||||
Json.Encode.object largeListJson
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
foldDedup list =
|
||||
let
|
||||
dedup ( name, val ) ( cache, ls ) =
|
||||
if Set.member name cache then
|
||||
( cache, ls )
|
||||
|
||||
else
|
||||
( Set.insert name cache, val :: ls )
|
||||
in
|
||||
List.foldl dedup ( Set.empty, [] ) list
|
||||
|> Tuple.second
|
||||
|
||||
|
||||
largeListInt =
|
||||
List.range 1 10000
|
||||
|> List.map
|
||||
(\i ->
|
||||
let
|
||||
wrappingI =
|
||||
modBy 50 i
|
||||
in
|
||||
( wrappingI, "elem-" ++ String.fromInt wrappingI )
|
||||
)
|
||||
|
||||
|
||||
largeList =
|
||||
List.range 1 10000
|
||||
|> List.map
|
||||
(\i ->
|
||||
let
|
||||
wrappingI =
|
||||
modBy 50 i
|
||||
in
|
||||
( "elem-" ++ String.fromInt wrappingI, "elem-" ++ String.fromInt wrappingI )
|
||||
)
|
||||
|
||||
|
||||
largeListJson =
|
||||
List.range 1 10000
|
||||
|> List.map
|
||||
(\i ->
|
||||
let
|
||||
wrappingI =
|
||||
modBy 50 i
|
||||
in
|
||||
( "elem-" ++ String.fromInt wrappingI, Json.Encode.string ("elem-" ++ String.fromInt wrappingI) )
|
||||
)
|
29
benchmarks/micro/elm.json
Normal file
29
benchmarks/micro/elm.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"."
|
||||
],
|
||||
"elm-version": "0.19.0",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.1",
|
||||
"elm/core": "1.0.2",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm/time": "1.0.0",
|
||||
"elm-explorations/benchmark": "1.0.1"
|
||||
},
|
||||
"indirect": {
|
||||
"BrianHicks/elm-trend": "2.1.2",
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user