Skip to content

Instantly share code, notes, and snippets.

@pzp1997
Last active June 15, 2017 15:48
Show Gist options
  • Save pzp1997/313b8c1563fb4938802c66742fa0f111 to your computer and use it in GitHub Desktop.
Save pzp1997/313b8c1563fb4938802c66742fa0f111 to your computer and use it in GitHub Desktop.
Benchmarking List.Extra.unique in Elm. https://ellie-app.com/3tWkXFK8pHfa1/2
module Main exposing (..)
{- import Html exposing (Html, text) -}
import Benchmark exposing (Benchmark, describe, compare, benchmark1)
import Benchmark.Runner exposing (BenchmarkProgram, program)
import List.Extra as List
import Set
setUnique : List comparable -> List comparable
setUnique =
Set.toList << Set.fromList
suite : Benchmark
suite =
let
tenInts =
[ 2, 7, 3, 2, 4, 7, 4, 8, 6, 1 ]
hundredIntsDense =
[ 9, 3, 3, 1, 0, 8, 7, 5, 6, 6, 1, 0, 4, 6, 1, 1, 0, 6, 5, 6, 4, 1, 0, 1, 9, 5, 4, 2, 1, 9, 1, 0, 3, 6, 5, 5, 3, 4, 9, 7, 3, 9, 3, 8, 7, 8, 9, 6, 2, 1, 0, 4, 1, 6, 5, 9, 1, 0, 4, 4, 4, 7, 2, 5, 1, 0, 1, 0, 5, 7, 9, 1, 7, 6, 4, 6, 5, 5, 5, 5, 1, 0, 8, 4, 5, 7, 1, 0, 5, 9, 4, 1, 0, 3, 7, 8, 9, 9, 7, 1, 6, 4, 3, 4, 3, 6, 7, 5, 8, 8, 2, 6 ]
hundredIntsSparse =
[ 2, 76, 58, 77, 97, 23, 6, 51, 41, 80, 53, 41, 96, 41, 76, 54, 64, 38, 15, 19, 21, 59, 71, 92, 7, 57, 79, 7, 92, 99, 52, 42, 67, 47, 13, 78, 29, 79, 12, 52, 89, 78, 17, 71, 87, 61, 14, 30, 45, 19, 9, 16, 33, 73, 90, 3, 83, 9, 78, 45, 16, 98, 20, 59, 60, 72, 71, 2, 14, 36, 95, 40, 63, 39, 81, 66, 47, 96, 6, 33, 19, 41, 33, 3, 34, 49, 8, 79, 8, 61, 49, 80, 74, 50, 23, 64, 16, 47, 52, 48 ]
thousandInts =
[ 94, 16, 6, 45, 2, 25, 24, 67, 20, 63, 8, 97, 57, 39, 71, 11, 1, 71, 90, 24, 94, 86, 14, 19, 9, 11, 18, 52, 51, 33, 98, 99, 35, 73, 66, 49, 95, 79, 68, 77, 69, 12, 10, 61, 31, 84, 38, 44, 61, 39, 66, 83, 21, 28, 42, 94, 53, 75, 13, 84, 74, 98, 63, 62, 90, 19, 25, 42, 64, 22, 6, 14, 27, 86, 4, 75, 77, 55, 48, 67, 87, 52, 70, 20, 37, 13, 34, 50, 76, 78, 35, 6, 44, 37, 88, 76, 81, 80, 10, 45, 40, 63, 91, 100, 72, 35, 26, 75, 12, 84, 87, 51, 20, 19, 48, 25, 72, 18, 17, 5, 42, 21, 73, 67, 100, 72, 72, 58, 29, 94, 73, 90, 13, 45, 32, 49, 42, 85, 16, 26, 76, 3, 88, 53, 43, 76, 17, 22, 14, 23, 40, 17, 47, 43, 40, 79, 8, 46, 70, 35, 34, 28, 85, 91, 65, 16, 16, 92, 9, 100, 7, 97, 46, 92, 11, 47, 88, 29, 82, 11, 13, 37, 36, 21, 24, 54, 54, 93, 87, 92, 86, 30, 7, 39, 31, 93, 61, 11, 13, 93, 80, 16, 88, 95, 33, 87, 36, 9, 97, 54, 69, 99, 100, 76, 95, 70, 30, 91, 84, 81, 54, 47, 54, 23, 10, 52, 63, 37, 35, 31, 57, 9, 30, 17, 15, 12, 69, 53, 19, 8, 43, 25, 86, 86, 56, 56, 18, 84, 63, 100, 11, 8, 26, 94, 3, 84, 49, 15, 4, 44, 33, 88, 41, 76, 78, 86, 43, 82, 6, 9, 14, 78, 71, 16, 73, 14, 61, 65, 31, 73, 43, 90, 73, 50, 68, 65, 49, 87, 39, 53, 4, 20, 12, 55, 11, 72, 35, 5, 54, 46, 32, 31, 3, 82, 23, 55, 17, 23, 72, 52, 43, 50, 77, 94, 56, 81, 89, 73, 58, 96, 4, 97, 15, 35, 75, 53, 61, 43, 48, 18, 13, 60, 2, 57, 40, 30, 31, 12, 39, 20, 64, 15, 73, 50, 10, 48, 54, 19, 37, 79, 11, 6, 75, 35, 47, 1, 55, 70, 51, 47, 60, 28, 41, 54, 10, 95, 19, 47, 32, 39, 40, 83, 37, 11, 84, 96, 99, 74, 80, 27, 82, 23, 84, 1, 60, 22, 38, 71, 88, 31, 42, 17, 24, 18, 10, 36, 97, 75, 24, 37, 17, 21, 88, 18, 15, 16, 70, 10, 18, 48, 51, 43, 42, 57, 64, 24, 81, 2, 36, 82, 4, 38, 21, 49, 4, 50, 99, 23, 9, 81, 18 ] ++ [ 76, 18, 28, 78, 91, 31, 83, 44, 10, 3, 98, 16, 62, 72, 31, 95, 6, 56, 36, 28, 63, 68, 48, 5, 90, 25, 50, 5, 52, 30, 18, 25, 46, 34, 80, 69, 70, 13, 35, 51, 35, 50, 75, 72, 63, 31, 71, 31, 88, 92, 80, 80, 73, 98, 88, 70, 76, 73, 14, 88, 61, 37, 78, 98, 8, 75, 26, 39, 11, 29, 4, 99, 91, 85, 95, 79, 13, 39, 38, 85, 90, 74, 81, 94, 77, 60, 97, 23, 33, 5, 1, 61, 66, 32, 15, 26, 71, 2, 7, 8, 50, 50, 32, 46, 24, 44, 49, 46, 94, 27, 31, 44, 88, 22, 92, 31, 81, 3, 28, 83, 20, 65, 97, 11, 68, 61, 43, 71, 5, 96, 57, 16, 81, 49, 96, 5, 30, 86, 80, 18, 76, 6, 4, 49, 67, 58, 54, 34, 72, 36, 62, 17, 67, 8, 68, 57, 56, 91, 52, 54, 21, 83, 91, 38, 61, 70, 97, 25, 36, 32, 89, 27, 79, 70, 15, 38, 24, 83, 27, 98, 83, 68, 18, 68, 57, 81, 81, 61, 86, 17, 9, 86, 2, 69, 86, 21, 87, 85, 41, 46, 13, 65, 70, 27, 62, 35, 85, 56, 44, 96, 55, 16, 90, 17, 74, 44, 4, 81, 28, 11, 19, 96, 10, 68, 67, 51, 68, 93, 63, 33, 87, 70, 61, 28, 85, 68, 93, 33, 51, 64, 49, 61, 3, 70, 18, 52, 76, 63, 52, 60, 16, 64, 21, 10, 28, 34, 16, 6, 15, 35, 95, 10, 63, 4, 96, 29, 100, 59, 38, 36, 13, 90, 20, 42, 94, 66, 2, 85, 9, 3, 47, 78, 69, 86, 19, 44, 18, 22, 79, 9, 4, 22, 3, 98, 7, 16, 92, 47, 9, 4, 4, 50, 88, 20, 84, 33, 18, 54, 1, 4, 31, 75, 40, 33, 38, 69, 86, 26, 36, 39, 80, 79, 11, 51, 39, 79, 43, 39, 3, 63, 42, 53, 88, 75, 100, 43, 25, 72, 73, 60, 74, 17, 4, 1, 78, 82, 44, 56, 86, 57, 58, 53, 85, 25, 90, 64, 79, 94, 78, 37, 57, 77, 89, 8, 99, 27, 97, 90, 85, 7, 10, 67, 30, 43, 97, 86, 55, 21, 38, 83, 91, 26, 35, 53, 52, 71, 25, 72, 30, 100, 14, 75, 76, 48, 25, 44, 56, 11, 33, 68, 55, 55, 96, 67, 56, 27, 51, 70, 27, 78, 22, 33, 92, 85, 36, 16, 20, 4, 17, 92, 62, 81, 42, 2, 95, 47, 32, 47, 92, 67, 23, 10, 98, 32, 22, 80, 62, 28, 54, 37, 56, 20, 17, 67, 57, 33, 24, 56, 73, 45, 93, 19, 8, 97, 58, 97, 45, 73, 78, 26, 15, 92, 99, 43, 89, 82, 14, 42, 2, 82, 19, 44, 28, 95, 47, 13, 100, 85, 33, 56, 13, 72, 24, 18, 100, 72, 84, 13, 8, 84, 21, 94, 9, 91, 81, 6, 26, 42, 89, 6, 35, 13, 20, 80, 72, 65, 76, 94, 100, 38, 8, 65, 48, 11, 49, 27, 74, 71, 59, 50, 95, 4, 17, 28, 26, 61, 65, 11, 11, 25, 75, 15, 36, 1, 18, 14, 1, 58, 22, 64, 86, 69, 35, 54, 11, 91, 66, 100, 20, 4, 25, 9, 52, 52, 27, 47, 62, 49, 36, 38, 35, 25, 40, 90, 40, 99, 79, 48, 60 ]
in
describe "unique"
[ Benchmark.compare "10 integers"
(benchmark1 "List.Extra.unique" List.unique tenInts)
(benchmark1 "setUnique" setUnique tenInts)
, Benchmark.compare "100 integers dense"
(benchmark1 "List.Extra.unique" List.unique hundredIntsDense)
(benchmark1 "setUnique" setUnique hundredIntsDense)
, Benchmark.compare "100 integers sparse"
(benchmark1 "List.Extra.unique" List.unique hundredIntsSparse)
(benchmark1 "setUnique" setUnique hundredIntsSparse)
, Benchmark.compare "1000 integers"
(benchmark1 "List.Extra.unique" List.unique thousandInts)
(benchmark1 "setUnique" setUnique thousandInts)
]
main : BenchmarkProgram
main =
program suite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment