-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use randomly structured Set and Map in benchmarks (#1075)
Trees constructed from [1..n] have a specific structure of perfect binary trees linked together. We shuffle the list so that the tree is generated from repeated insertions instead, which forms a random structure that should be more representative of average use cases. Most benchmarks show an increase in measured times, the amount varying from 10% to 70%. This is expected because the trees are more unbalanced now. A handful of benchmarks show larger increases. These were previously measuring best-case scenarios, which no longer occur with random trees.
- Loading branch information
Showing
6 changed files
with
84 additions
and
28 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
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
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,22 @@ | ||
module Utils.Random | ||
( shuffle | ||
) where | ||
|
||
import Data.List (unfoldr) | ||
import qualified Data.Sequence as Seq | ||
import System.Random (StdGen, mkStdGen, randomR) | ||
|
||
-- O(n log n). Deterministic shuffle. Implements Fisher-Yates. | ||
shuffle :: [a] -> [a] | ||
shuffle xs0 = unfoldr f (gen, Seq.fromList xs0) | ||
where | ||
f (g, xs) | ||
| Seq.null xs = Nothing | ||
| otherwise = Just (x, (g', xs')) | ||
where | ||
(i, g') = randomR (0, Seq.length xs - 1) g | ||
x = Seq.index xs i | ||
xs' = Seq.deleteAt i xs | ||
|
||
gen :: StdGen | ||
gen = mkStdGen 42 |
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