Created
July 15, 2019 14:06
-
-
Save joakin/66314080579fc35c3d434de3df67876b to your computer and use it in GitHub Desktop.
Mapping and making lists Benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mapList = | |
let | |
xs = | |
List.range 0 1000 |> List.map (always 0) | |
in | |
benchmark "List.map" | |
(\_ -> | |
xs |> List.map (always 1) | |
) | |
mapArray = | |
let | |
xs = | |
List.range 0 1000 |> List.map (always 0) |> Array.fromList | |
in | |
benchmark "Array.map" | |
(\_ -> | |
xs |> Array.map (always 1) | |
) | |
mapDict = | |
let | |
xs = | |
List.range 0 1000 |> List.map (\i -> ( i, 0 )) |> Dict.fromList | |
in | |
benchmark "Dict.map" | |
(\_ -> | |
xs |> Dict.map (\k x -> 1) | |
) | |
foldrList = | |
let | |
xs = | |
List.range 0 1000 |> List.map (always 0) | |
in | |
benchmark "List.foldr to make a list" | |
(\_ -> | |
List.foldr (\x acc -> x :: acc) xs [] | |
) | |
foldrArray = | |
let | |
xs = | |
List.range 0 1000 |> List.map (always 0) |> Array.fromList | |
in | |
benchmark "Array.foldr to make a list" | |
(\_ -> | |
Array.foldr (\x acc -> x :: acc) [] xs | |
) | |
foldrDict = | |
let | |
xs = | |
List.range 0 1000 |> List.map (\i -> ( i, 0 )) |> Dict.fromList | |
in | |
benchmark "Dict.foldr to make a list" | |
(\_ -> | |
Dict.foldr (\k x acc -> x :: acc) [] xs | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment