Pre-proposal discussion: add a version of dropWhileEnd with different laziness properties to Data.List

David Feuer david.feuer at gmail.com
Mon Sep 29 04:20:55 UTC 2014


Since so many people like to see benchmarks, I figured I'd give you
some. I tested

nf (unlines . dropWhile__ isSpace . lines) li__

li1 is a lorem ipsum produced by an online lorem ipsum generator. li4
is the same thing, but with each space replaced by a bunch of spaces.

dwr is dropWhileEndLE isSpace
rdr is reverse . dropWhile isSpace . reverse
dwe is dropWhileEnd isSpace

The poor performance of dwe compared to rdr in li1 seems most likely
to be caused by excessive use of isSpace, which takes quite a few
tests to determine that a character is *not* a space. The prevalence
of ' ' characters in li4 makes this less substantial. The difference
between dwr and rdr is relatively small in li1, but it jumps way up in
li4. I'm guessing this is because rdr sprays the entire string onto
the heap before filtering out most of it, whereas dwr pushes
everything onto the stack and only puts what it actually produces onto
the heap. In any case, I think these demonstrate the practical utility
of dropWhileEndLE for code that chooses to use lists for such
purposes.

benchmarking li1/dwr
time                 4.436 ms   (4.405 ms .. 4.465 ms)
                     1.000 R²   (0.999 R² .. 1.000 R²)
mean                 4.483 ms   (4.481 ms .. 4.487 ms)
std dev              9.562 μs   (6.414 μs .. 14.38 μs)

benchmarking li1/rdr
time                 5.061 ms   (5.053 ms .. 5.071 ms)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 5.062 ms   (5.059 ms .. 5.069 ms)
std dev              15.05 μs   (7.515 μs .. 24.65 μs)

benchmarking li1/dwe
time                 8.448 ms   (8.441 ms .. 8.460 ms)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 8.450 ms   (8.444 ms .. 8.464 ms)
std dev              24.61 μs   (10.83 μs .. 46.48 μs)


benchmarking li4/dwr
time                 19.52 ms   (17.23 ms .. 21.93 ms)
                     0.919 R²   (0.861 R² .. 0.983 R²)
mean                 18.11 ms   (17.16 ms .. 19.46 ms)
std dev              2.683 ms   (1.772 ms .. 3.495 ms)
variance introduced by outliers: 67% (severely inflated)

benchmarking li4/rdr
time                 29.63 ms   (27.63 ms .. 31.69 ms)
                     0.980 R²   (0.955 R² .. 0.993 R²)
mean                 30.03 ms   (28.31 ms .. 32.27 ms)
std dev              4.152 ms   (2.719 ms .. 5.921 ms)
variance introduced by outliers: 57% (severely inflated)

benchmarking li4/dwe
time                 28.52 ms   (27.40 ms .. 29.72 ms)
                     0.994 R²   (0.990 R² .. 0.997 R²)
mean                 27.99 ms   (26.08 ms .. 28.94 ms)
std dev              2.961 ms   (1.437 ms .. 5.016 ms)
variance introduced by outliers: 43% (moderately inflated)


More information about the Libraries mailing list