Created
January 11, 2023 17:05
-
-
Save Janiczek/67a106dbfdd18d029f99522868bd5126 to your computer and use it in GitHub Desktop.
Benchmark List.init
This file contains 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
module Main exposing (..) | |
import Benchmark as Bench exposing (Benchmark) | |
import Benchmark.Runner.Alternative as Runner exposing (Program) | |
main : Program | |
main = | |
Runner.program suite | |
suite : Benchmark | |
suite = | |
let | |
items = | |
List.range 1 1000 | |
in | |
Bench.compare "init" | |
"reverse >> drop 1 >> reverse" | |
(\_ -> reverseStrategy items) | |
"length >> take" | |
(\_ -> takeStrategy) | |
reverseStrategy items = | |
case items of | |
[] -> | |
Nothing | |
nonEmptyList -> | |
nonEmptyList | |
|> List.reverse | |
|> List.tail | |
|> Maybe.map List.reverse | |
takeStrategy items = | |
List.take (List.length items - 1) items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment