Skip to content
  • Marcin Szamotulski's avatar
    Make Map's and Set's: foldr' & firends ' more strict · f00aa025
    Marcin Szamotulski authored and David Feuer's avatar David Feuer committed
    * 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)
    ```
    f00aa025