Skip to content

Commit

Permalink
[#8] Add docs for benchmark suite
Browse files Browse the repository at this point in the history
  • Loading branch information
pgujjula committed May 10, 2024
1 parent 97cf987 commit 12ed828
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 0 deletions.
1 change: 1 addition & 0 deletions apply-merge.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extra-doc-files:
README.md
ChangeLog.md
docs/ALGORITHM.md
docs/Benchmark.md
LICENSES/BSD-3-Clause.txt

source-repository head
Expand Down
202 changes: 202 additions & 0 deletions docs/Benchmark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
We benchmark the performance of the `applyMerge` implementations on different
"shapes" of generated elements.

* Linear: `applyMerge const [1..] [1..]`
<details>
<summary>Shape</summary>

. . . . . . . . . . . . . . .
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
</details>

* Triangular `applyMerge (+) [1..] [1..]`
<details>
<summary>Shape</summary>

. . . . . . . . . . . . . . *
. . . . . . . . . . . . . * *
. . . . . . . . . . . . * * *
. . . . . . . . . . . * * * *
. . . . . . . . . . * * * * *
. . . . . . . . . * * * * * *
. . . . . . . . * * * * * * *
. . . . . . . * * * * * * * *
. . . . . . . * * * * * * * *
. . . . . . * * * * * * * * *
. . . . . * * * * * * * * * *
. . . . * * * * * * * * * * *
. . . * * * * * * * * * * * *
. . * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
</details>

* Skewed triangular `applyMerge (\x y -> 4 * x + y) [1..] [1..]`
<details>
<summary>Shape</summary>

. . . . . . . . . . . . . . *
. . . . . . . . . . * * * * *
. . . . . . * * * * * * * * *
. . * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
</details>

* Hyperbolic: `applyMerge (*) [1..] [1..]`
<details>
<summary>Shape</summary>

. . . . . . . . . . . . . . .
. . . . . . . * * * * * * * *
. . . . . * * * * * * * * * *
. . . * * * * * * * * * * * *
. . . * * * * * * * * * * * *
. . * * * * * * * * * * * * *
. . * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
</summary>
</details>

* Skewed hyperbolic `applyMerge (\x y -> x^3 * y) [1..]`
<details>
<summary>Shape</summary>

. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . * * * * * *
. . . * * * * * * * * * * * *
. . * * * * * * * * * * * * *
. * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
</details>

* Circular: `applyMerge (\x y -> x*x + y*y) [1..]`
<details>
<summary>Shape</summary>

. . . . . . . . . . . . . * *
. . . . . . . . . . . . . * *
. . . . . . . . . . . . . * *
. . . . . . . . . . . . . * *
. . . . . . . . . . . . * * *
. . . . . . . . . . . . * * *
. . . . . . . . . . . * * * *
. . . . . . . . . . . * * * *
. . . . . . . . . . * * * * *
. . . . . . . . . * * * * * *
. . . . . . . . * * * * * * *
. . . . . . * * * * * * * * *
. . . . * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
</details>

* Elliptical: `applyMerge (\x y -> 4*x*x + y*y) [1..]`
<details>
<summary>Shape</summary>

. . . . . . . . . . . . . . *
. . . . . . . . . . . . . * *
. . . . . . . . . . . . . * *
. . . . . . . . . . . . * * *
. . . . . . . . . . * * * * *
. . . . . . . * * * * * * * *
. . . * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
</details>

* Composites:

We can generate prime numbers using the Sieve of Erastosthenes:
````haskell
primes :: [Int]
primes = 2 : ([3..] `minus` composites) -- `minus` from data-ordlist

composites :: [Int]
composites = applyMerge (\p i -> p * (p + i)) primes [0..]
````

The shape of `composites` then looks like:
<details>
<summary>Shape</summary>

. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . * * * *
. . . . * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
</details>

Since the *n*th prime number is approximately *n* log *n*, this is a
quasi-hyperbolic shape, roughly equivalent to

```haskell
f :: Int -> Int -> Double
f x y =
let x' :: Double
x' = fromIntegral x

y' :: Double
y' = fromIntegral y

xlogx :: Double
xlogx = x' * log x'
in xlogx * (xlogx + y')

compositesApprox :: [Double]
compositesApprox = applyMerge f [1..] [1..]
```
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extra-doc-files:
- README.md
- ChangeLog.md
- docs/ALGORITHM.md
- docs/Benchmark.md
- LICENSES/BSD-3-Clause.txt

language: GHC2021
Expand Down

0 comments on commit 12ed828

Please sign in to comment.