-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
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
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
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..] | ||
``` |
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