Skip to content

Commit 36912fe

Browse files
committed
Add benchmark
1 parent 5743fa9 commit 36912fe

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

benchmark/Main.hs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module Main where
2+
3+
import Criterion.Main (bench, bgroup, defaultMain, nf)
4+
import Data.List.Extra
5+
6+
main :: IO ()
7+
main = defaultMain
8+
[ bgroup "nubOrd"
9+
[ bench "Int: Many repeats" $ nf nubOrd intMany
10+
, bench "Int: Few repeats " $ nf nubOrd intFew
11+
, bench "String: Many repeats" $ nf nubOrd stringMany
12+
, bench "String: Few repeats" $ nf nubOrd stringFew
13+
]
14+
]
15+
16+
inputSize :: Int
17+
inputSize = 100000
18+
19+
intMany :: [Int]
20+
intMany = take inputSize (cycle [1..1000])
21+
22+
intFew :: [Int]
23+
intFew = take inputSize (cycle [1..100000])
24+
25+
stringMany :: [String]
26+
stringMany =
27+
let
28+
prefix = replicate 52 (replicate 10 'h')
29+
alphabet = fmap pure (['a'..'z'] <> ['A' .. 'Z'])
30+
input = zipWith (<>) prefix alphabet
31+
in
32+
take inputSize (cycle input)
33+
34+
stringFew :: [String]
35+
stringFew =
36+
let
37+
common = [ "the" , "at" , "there", "some" , "my"
38+
, "of" , "be" , "use" , "her" , "than"
39+
, "and" , "this", "an" , "would" , "first"
40+
, "a" , "have", "each" , "make" , "water"
41+
, "to" , "from", "which", "like" , "been"
42+
, "in" , "or" , "she" , "him" , "call"
43+
, "is" , "one", "do" , "into" , "who"
44+
, "you" , "had", "how" , "time" , "oil"
45+
, "that", "by" , "their", "has" , "its"
46+
, "it" , "word", "if" , "look" , "now"
47+
, "he" , "but", "will" , "two" , "find"
48+
, "was" , "not", "up" , "more" , "long"
49+
, "for" , "what", "other", "write" , "down"
50+
, "on" , "all", "about", "go" , "day"
51+
, "are" , "were", "out" , "see" , "did"
52+
, "as" , "we" , "many" , "number", "get"
53+
, "with", "when", "then" , "no" , "come"
54+
, "his" , "your", "them" , "way" , "made"
55+
, "they", "can", "these", "could" , "may"
56+
, "I" , "said", "so" , "people", "part"
57+
]
58+
addTicks :: Int -> [String] -> [String]
59+
addTicks 0 ls = ls
60+
addTicks n ls = ls <> fmap (<> "'") ls <> addTicks (n - 1) ls
61+
62+
input = addTicks 100 common
63+
in
64+
take inputSize (cycle input)

benchmark/cabal.project

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: ../extra.cabal extra-benchmarks.cabal

benchmark/extra-benchmarks.cabal

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Name: extra-benchmarks
2+
Version: 0.1
3+
License: BSD3
4+
License-File: LICENSE
5+
author: Neil Mitchell <[email protected]>
6+
maintainer: Neil Mitchell <[email protected]>
7+
copyright: Neil Mitchell 2014-2019
8+
Cabal-Version: >= 1.2
9+
Build-Type: Simple
10+
11+
Executable bench
12+
Main-Is: Main.hs
13+
14+
Build-Depends:
15+
base >= 2 && < 5,
16+
criterion,
17+
extra
18+
19+
Ghc-Options:
20+
-O2
21+
22+
Other-Modules:

0 commit comments

Comments
 (0)