-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Map's and Set's: foldr' & firends ' more strict
* Map.foldr' * Map.foldl' * Map.foldrWithKey' * Map.foldlWithKey' * Set.foldr' * Set.foldl' They now evaluate intermediate results of the accumulator before appling the folding operator again. This patch contains tests based on `nothunks` library. Benchmark summary: Map old: ``` benchmarking foldlWithKey' ... benchmarked foldlWithKey' time 28.57 μs (28.00 μs .. 29.35 μs) 0.991 R² (0.979 R² .. 0.999 R²) mean 28.43 μs (28.12 μs .. 28.99 μs) std dev 1.358 μs (729.0 ns .. 2.101 μs) variance introduced by outliers: 27% (moderately inflated) benchmarking foldrWithKey' ... benchmarked foldrWithKey' time 80.25 ns (79.45 ns .. 81.13 ns) 0.998 R² (0.996 R² .. 0.999 R²) mean 79.84 ns (79.27 ns .. 80.68 ns) std dev 2.184 ns (1.572 ns .. 2.921 ns) variance introduced by outliers: 11% (moderately inflated) ``` Map new: ``` benchmarking foldlWithKey' ... benchmarked foldlWithKey' time 27.76 μs (27.15 μs .. 28.34 μs) 0.996 R² (0.992 R² .. 0.998 R²) mean 27.08 μs (26.84 μs .. 27.43 μs) std dev 964.2 ns (720.7 ns .. 1.350 μs) variance introduced by outliers: 18% (moderately inflated) benchmarking foldrWithKey' ... benchmarked foldrWithKey' time 74.02 ns (73.01 ns .. 75.82 ns) 0.998 R² (0.994 R² .. 1.000 R²) mean 73.14 ns (72.91 ns .. 73.80 ns) std dev 1.245 ns (434.3 ps .. 2.625 ns) ``` Set old: ```benchmarking member ... benchmarked member time 237.1 μs (231.5 μs .. 246.0 μs) 0.993 R² (0.986 R² .. 0.999 R²) mean 234.3 μs (232.1 μs .. 238.0 μs) std dev 9.031 μs (5.737 μs .. 15.46 μs) variance introduced by outliers: 20% (moderately inflated) ``` Set new: ``` benchmarking member ... benchmarked member time 219.4 μs (216.3 μs .. 222.6 μs) 0.999 R² (0.997 R² .. 1.000 R²) mean 221.3 μs (219.3 μs .. 225.3 μs) std dev 10.25 μs (5.408 μs .. 18.71 μs) variance introduced by outliers: 28% (moderately inflated) ```
- Loading branch information
Showing
10 changed files
with
188 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Utils.NoThunks (whnfHasNoThunks) where | ||
|
||
import Data.Maybe (isNothing) | ||
|
||
import NoThunks.Class (NoThunks, noThunks) | ||
import Test.QuickCheck (Property, ioProperty) | ||
|
||
-- | Check that after evaluating the argument to weak head normal form there | ||
-- are no thunks. | ||
-- | ||
whnfHasNoThunks :: NoThunks a => a -> Property | ||
whnfHasNoThunks a = ioProperty | ||
. fmap isNothing | ||
. noThunks [] | ||
$! a |
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
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
Oops, something went wrong.