Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Created January 11, 2023 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janiczek/67a106dbfdd18d029f99522868bd5126 to your computer and use it in GitHub Desktop.
Save Janiczek/67a106dbfdd18d029f99522868bd5126 to your computer and use it in GitHub Desktop.
Benchmark List.init
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